From 500093ef89387aead8be8086e33c05fa250446e9 Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Wed, 7 Jan 2009 15:49:08 -0600 Subject: 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. --- libempathy-gtk/empathy-chat.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libempathy-gtk/empathy-chat.c') 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); -- cgit v1.2.3