aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
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
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')
-rw-r--r--libempathy/empathy-contact-list.c9
-rw-r--r--libempathy/empathy-tp-chat.c95
2 files changed, 104 insertions, 0 deletions
diff --git a/libempathy/empathy-contact-list.c b/libempathy/empathy-contact-list.c
index d9493af1e..d4859210a 100644
--- a/libempathy/empathy-contact-list.c
+++ b/libempathy/empathy-contact-list.c
@@ -54,6 +54,15 @@ contact_list_base_init (gpointer klass)
static gboolean initialized = FALSE;
if (!initialized) {
+ g_signal_new ("member-renamed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ _empathy_marshal_VOID__OBJECT_OBJECT_UINT_STRING,
+ G_TYPE_NONE,
+ 4, EMPATHY_TYPE_CONTACT, EMPATHY_TYPE_CONTACT, G_TYPE_UINT, G_TYPE_STRING);
+
g_signal_new ("members-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index aa8c1a1c5..aebeb6670 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -946,6 +946,83 @@ chat_lookup_contact (EmpathyTpChat *chat,
return NULL;
}
+typedef struct
+{
+ TpHandle old_handle;
+ guint reason;
+ const gchar *message;
+} ContactRenameData;
+
+static ContactRenameData*
+contact_rename_data_new (TpHandle handle,
+ guint reason,
+ const gchar* message)
+{
+ ContactRenameData *data = g_new (ContactRenameData, 1);
+ data->old_handle = handle;
+ data->reason = reason;
+ data->message = message;
+
+ return data;
+}
+
+static void
+contact_rename_data_free (ContactRenameData* data)
+{
+ g_free (data);
+}
+
+static void
+tp_chat_got_renamed_contacts_cb (EmpathyTpContactFactory *factory,
+ guint n_contacts,
+ EmpathyContact * const * contacts,
+ guint n_failed,
+ const TpHandle *failed,
+ const GError *error,
+ gpointer user_data,
+ GObject *chat)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (chat);
+ const TpIntSet *members;
+ TpHandle handle;
+ EmpathyContact *old = NULL, *new = NULL;
+
+ if (error) {
+ DEBUG ("Error: %s", error->message);
+ return;
+ }
+
+ /* renamed members can only be delivered one at a time */
+ g_warn_if_fail (n_contacts == 1);
+
+ ContactRenameData *rename_data = (ContactRenameData*) user_data;
+
+ new = contacts[0];
+
+ members = tp_channel_group_get_members (priv->channel);
+ handle = empathy_contact_get_handle (new);
+
+ old = chat_lookup_contact (EMPATHY_TP_CHAT (chat),
+ rename_data->old_handle, TRUE);
+
+ /* Make sure the contact is still member */
+ if (tp_intset_is_member (members, handle)) {
+ priv->members = g_list_prepend (priv->members,
+ g_object_ref (new));
+
+ if (old != NULL) {
+ g_signal_emit_by_name (chat, "member-renamed",
+ old, new, rename_data->reason,
+ rename_data->message);
+ g_object_unref (old);
+ }
+ }
+
+ tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
+ tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
+}
+
+
static void
tp_chat_group_members_changed_cb (TpChannel *self,
gchar *message,
@@ -961,6 +1038,24 @@ tp_chat_group_members_changed_cb (TpChannel *self,
EmpathyContact *contact;
EmpathyContact *actor_contact = NULL;
guint i;
+ ContactRenameData *rename_data;
+
+ /* Contact renamed */
+ if (reason == TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED) {
+ /* there can only be a single 'added' and a single 'removed' handle */
+ g_warn_if_fail(removed->len == 1);
+ g_warn_if_fail(added->len == 1);
+
+ TpHandle old_handle = g_array_index (removed, guint, 0);
+
+ rename_data = contact_rename_data_new (old_handle, reason, message);
+ empathy_tp_contact_factory_get_from_handles (priv->factory,
+ added->len, (TpHandle *) added->data,
+ tp_chat_got_renamed_contacts_cb,
+ rename_data, (GDestroyNotify) contact_rename_data_free,
+ G_OBJECT (chat));
+ return;
+ }
if (actor != 0) {
actor_contact = chat_lookup_contact (chat, actor, FALSE);