aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@gnome.org>2009-01-08 05:49:08 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-11-19 03:09:34 +0800
commit500093ef89387aead8be8086e33c05fa250446e9 (patch)
treeef67732138768286eb3c6dcee88bc8983316015c /libempathy-gtk
parent79fcbc9965a60f8099ea355188b954ae2444eddc (diff)
downloadgsoc2013-empathy-500093ef89387aead8be8086e33c05fa250446e9.tar
gsoc2013-empathy-500093ef89387aead8be8086e33c05fa250446e9.tar.gz
gsoc2013-empathy-500093ef89387aead8be8086e33c05fa250446e9.tar.bz2
gsoc2013-empathy-500093ef89387aead8be8086e33c05fa250446e9.tar.lz
gsoc2013-empathy-500093ef89387aead8be8086e33c05fa250446e9.tar.xz
gsoc2013-empathy-500093ef89387aead8be8086e33c05fa250446e9.tar.zst
gsoc2013-empathy-500093ef89387aead8be8086e33c05fa250446e9.zip
Handle the case where a user's id changes in a chatroom
Telepathy-glib has a enum value for the MembersChanged signal to signify that a user's ID has changed. Previously, empathy was simply interpreting this as if a user with the old name had left the chat and a different user with the new name had entered the chat. This change handles this case more gracefully by updating the contact's id (and name) when this change reason is present One thing that does not yet work with this patch is if you are engaged in a private chat with a person and they change their nick in the middle of the chat. Then the EmpathyContact* that you are chatting with is no longer the EmpathyContact* representing the remote user, so messages won't be delivered properly. When we detect that a user has been 'renamed', we probably need to somehow go through all of the private chats with that person and swap out the old (invalid) EmpathyContact* and replace it with the new one so that the chat can continue without interruption.
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-chat.c29
-rw-r--r--libempathy-gtk/empathy-contact-list-store.c56
2 files changed, 85 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 07bd35711..cc946b1e1 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -1791,6 +1791,8 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat,
gboolean is_member,
EmpathyChat *chat)
{
+ g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED != reason);
+
EmpathyChatPriv *priv = GET_PRIV (chat);
const gchar *name = empathy_contact_get_name (contact);
gchar *str;
@@ -1809,6 +1811,30 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat,
g_free (str);
}
+static void
+chat_member_renamed_cb (EmpathyTpChat *tp_chat,
+ EmpathyContact *old_contact,
+ EmpathyContact *new_contact,
+ guint reason,
+ gchar *message,
+ EmpathyChat *chat)
+{
+ g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED == reason);
+
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ if (priv->block_events_timeout_id == 0) {
+ gchar *str;
+
+ str = g_strdup_printf (_("%s is now known as %s"),
+ empathy_contact_get_name (old_contact),
+ empathy_contact_get_name (new_contact));
+ empathy_chat_view_append_event (chat->view, str);
+ g_free (str);
+ }
+
+}
+
static gboolean
chat_reset_size_request (gpointer widget)
{
@@ -2536,6 +2562,9 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
g_signal_connect (tp_chat, "members-changed",
G_CALLBACK (chat_members_changed_cb),
chat);
+ g_signal_connect (tp_chat, "member-renamed",
+ G_CALLBACK (chat_member_renamed_cb),
+ chat);
g_signal_connect_swapped (tp_chat, "notify::remote-contact",
G_CALLBACK (chat_remote_contact_changed_cb),
chat);
diff --git a/libempathy-gtk/empathy-contact-list-store.c b/libempathy-gtk/empathy-contact-list-store.c
index 6572b4c90..417250fcd 100644
--- a/libempathy-gtk/empathy-contact-list-store.c
+++ b/libempathy-gtk/empathy-contact-list-store.c
@@ -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,
@@ -175,6 +181,10 @@ contact_list_store_iface_setup (gpointer user_data)
/* 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),
store);
@@ -309,6 +319,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);
g_signal_handlers_disconnect_by_func (priv->list,
@@ -835,6 +848,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,
gchar *group,