]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-list-store.c
Handle the case where a user's id changes in a chatroom
[empathy.git] / libempathy-gtk / empathy-contact-list-store.c
index 6572b4c908a0e4bd8b683467992441d2d1a6453a..417250fcd7fa879cfa9f49110fdcb044858f7b05 100644 (file)
@@ -103,6 +103,12 @@ static void             contact_list_store_members_changed_cb        (EmpathyCon
                                                                      gchar                         *message,
                                                                      gboolean                       is_member,
                                                                      EmpathyContactListStore       *store);
+static void             contact_list_store_member_renamed_cb         (EmpathyContactList            *list_iface,
+                                                                     EmpathyContact                *old_contact,
+                                                                     EmpathyContact                *new_contact,
+                                                                     guint                          reason,
+                                                                     gchar                         *message,
+                                                                     EmpathyContactListStore       *store);
 static void             contact_list_store_groups_changed_cb         (EmpathyContactList            *list_iface,
                                                                      EmpathyContact                *contact,
                                                                      gchar                         *group,
@@ -174,6 +180,10 @@ contact_list_store_iface_setup (gpointer user_data)
        GList                       *contacts, *l;
 
        /* Signal connection. */
+       g_signal_connect (priv->list,
+                         "member-renamed",
+                         G_CALLBACK (contact_list_store_member_renamed_cb),
+                         store);
        g_signal_connect (priv->list,
                          "members-changed",
                          G_CALLBACK (contact_list_store_members_changed_cb),
@@ -308,6 +318,9 @@ contact_list_store_dispose (GObject *object)
        }
        g_list_free (contacts);
 
+       g_signal_handlers_disconnect_by_func (priv->list,
+                                             G_CALLBACK (contact_list_store_member_renamed_cb),
+                                             object);
        g_signal_handlers_disconnect_by_func (priv->list,
                                              G_CALLBACK (contact_list_store_members_changed_cb),
                                              object);
@@ -834,6 +847,49 @@ contact_list_store_members_changed_cb (EmpathyContactList      *list_iface,
        }
 }
 
+static void
+contact_list_store_member_renamed_cb (EmpathyContactList      *list_iface,
+                                     EmpathyContact          *old_contact,
+                                     EmpathyContact          *new_contact,
+                                     guint                    reason,
+                                     gchar                   *message,
+                                     EmpathyContactListStore *store)
+{
+       EmpathyContactListStorePriv *priv;
+
+       priv = GET_PRIV (store);
+
+       DEBUG ("Contact %s (%d) renamed to %s (%d)",
+               empathy_contact_get_id (old_contact),
+               empathy_contact_get_handle (old_contact),
+               empathy_contact_get_id (new_contact),
+               empathy_contact_get_handle (new_contact));
+
+       /* connect to signals of new contact */
+       g_signal_connect (new_contact, "notify::presence",
+                         G_CALLBACK (contact_list_store_contact_updated_cb),
+                         store);
+       g_signal_connect (new_contact, "notify::presence-message",
+                         G_CALLBACK (contact_list_store_contact_updated_cb),
+                         store);
+       g_signal_connect (new_contact, "notify::name",
+                         G_CALLBACK (contact_list_store_contact_updated_cb),
+                         store);
+       g_signal_connect (new_contact, "notify::avatar",
+                         G_CALLBACK (contact_list_store_contact_updated_cb),
+                         store);
+       g_signal_connect (new_contact, "notify::capabilities",
+                         G_CALLBACK (contact_list_store_contact_updated_cb),
+                         store);
+       contact_list_store_add_contact (store, new_contact);
+
+       /* disconnect from old contact */
+       g_signal_handlers_disconnect_by_func (old_contact,
+                                             G_CALLBACK (contact_list_store_contact_updated_cb),
+                                             store);
+       contact_list_store_remove_contact (store, old_contact);
+}
+
 static void
 contact_list_store_groups_changed_cb (EmpathyContactList      *list_iface,
                                      EmpathyContact          *contact,