Commit 8d37a713 authored by Mohammed Sadiq's avatar Mohammed Sadiq

new-muc-dialog: Validate group name one creation

parent c31fcee5
Pipeline #58345 failed with stages
in 8 minutes and 28 seconds
......@@ -19,11 +19,6 @@
#include "chatty-new-muc-dialog.h"
static void chatty_new_muc_name_check (ChattyNewMucDialog *self,
GtkEntry *entry,
GtkWidget *button);
struct _ChattyNewMucDialog
{
HdyDialog parent_instance;
......@@ -108,11 +103,30 @@ button_join_chat_clicked_cb (ChattyNewMucDialog *self)
static void
chat_name_changed_cb (ChattyNewMucDialog *self)
{
g_assert (CHATTY_IS_NEW_MUC_DIALOG(self));
PurpleAccount *account;
const char *name;
gboolean valid = FALSE;
g_assert (CHATTY_IS_NEW_MUC_DIALOG (self));
name = gtk_entry_get_text (GTK_ENTRY (self->entry_group_chat_id));
account = chatty_pp_account_get_account (self->selected_account);
chatty_new_muc_name_check (self,
GTK_ENTRY(self->entry_group_chat_id),
self->button_join_chat);
if (account && name && *name)
if (!purple_find_buddy (account, name))
valid = TRUE;
/* Try harder to invalidate */
if (valid) {
ChattyProtocol protocol;
protocol = chatty_item_get_protocols (CHATTY_ITEM (self->selected_account));
if (!chatty_utils_groupname_is_valid (name, protocol))
valid = FALSE;
}
gtk_widget_set_sensitive (self->button_join_chat, valid);
}
......@@ -134,34 +148,6 @@ account_list_row_activated_cb (ChattyNewMucDialog *self,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(prefix_radio), TRUE);
}
static void
chatty_new_muc_name_check (ChattyNewMucDialog *self,
GtkEntry *entry,
GtkWidget *button)
{
PurpleAccount *account;
PurpleBuddy *buddy = NULL;
const char *name;
g_return_if_fail (CHATTY_IS_NEW_MUC_DIALOG(self));
name = gtk_entry_get_text (entry);
account = chatty_pp_account_get_account (self->selected_account);
if ((*name != '\0') && account) {
buddy = purple_find_buddy (account, name);
}
if ((*name != '\0') && !buddy) {
gtk_widget_set_sensitive (button, TRUE);
} else {
gtk_widget_set_sensitive (button, FALSE);
}
}
static void
chatty_new_muc_add_account_to_list (ChattyNewMucDialog *self,
ChattyPpAccount *account)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment