From cbfe2006c6b8e0fae731cd26c0284d7767fc4662 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 18 Jun 2009 11:04:40 +0100 Subject: Include actor in members-changed if possible --- libempathy/empathy-tp-chat.c | 65 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 14 deletions(-) (limited to 'libempathy/empathy-tp-chat.c') diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 794e3e3b7..1bee75ed8 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -875,6 +875,33 @@ tp_chat_got_added_contacts_cb (EmpathyTpContactFactory *factory, tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat)); } +static EmpathyContact * +chat_lookup_contact (EmpathyTpChat *chat, + TpHandle handle, + gboolean remove) +{ + EmpathyTpChatPriv *priv = GET_PRIV (chat); + GList *l; + + for (l = priv->members; l; l = l->next) { + EmpathyContact *c = l->data; + + if (empathy_contact_get_handle (c) == handle) { + if (remove) { + /* Caller takes the reference. */ + priv->members = g_list_delete_link ( + priv->members, l); + } else { + g_object_ref (c); + } + + return c; + } + } + + return NULL; +} + static void tp_chat_group_members_changed_cb (TpChannel *self, gchar *message, @@ -887,24 +914,30 @@ tp_chat_group_members_changed_cb (TpChannel *self, EmpathyTpChat *chat) { EmpathyTpChatPriv *priv = GET_PRIV (chat); - EmpathyContact *contact; - TpHandle handle; + EmpathyContact *contact, *actor_contact = NULL; guint i; - GList *l; + + if (actor != 0) { + actor_contact = chat_lookup_contact (chat, actor, FALSE); + if (actor_contact == NULL) { + /* TODO: handle this a tad more gracefully: perhaps the + * actor was a server op. We could use the contact-ids + * detail of MembersChangedDetailed. + */ + DEBUG ("actor %u not a channel member", actor); + } + } /* Remove contacts that are not members anymore */ for (i = 0; i < removed->len; i++) { - for (l = priv->members; l; l = l->next) { - contact = l->data; - handle = empathy_contact_get_handle (contact); - if (handle == g_array_index (removed, TpHandle, i)) { - priv->members = g_list_delete_link (priv->members, l); - g_signal_emit_by_name (chat, "members-changed", - contact, NULL, reason, - message, FALSE); - g_object_unref (contact); - break; - } + contact = chat_lookup_contact (chat, + g_array_index (removed, TpHandle, i), TRUE); + + if (contact != NULL) { + g_signal_emit_by_name (chat, "members-changed", contact, + actor_contact, reason, message, + FALSE); + g_object_unref (contact); } } @@ -917,6 +950,10 @@ tp_chat_group_members_changed_cb (TpChannel *self, } tp_chat_update_remote_contact (chat); + + if (actor_contact != NULL) { + g_object_unref (actor_contact); + } } static void -- cgit v1.2.3 From 367084af410d31a3fa8a9f040dd70ba5238816f4 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 18 Jun 2009 21:26:41 +0100 Subject: Coding style: one declaration per line. --- libempathy/empathy-tp-chat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libempathy/empathy-tp-chat.c') diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 1bee75ed8..1df1cf8a9 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -914,7 +914,8 @@ tp_chat_group_members_changed_cb (TpChannel *self, EmpathyTpChat *chat) { EmpathyTpChatPriv *priv = GET_PRIV (chat); - EmpathyContact *contact, *actor_contact = NULL; + EmpathyContact *contact; + EmpathyContact *actor_contact = NULL; guint i; if (actor != 0) { -- cgit v1.2.3 From a0813b0a5b90e959994f0f6f029af30364ddd258 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 18 Jun 2009 21:26:50 +0100 Subject: Style: use FIXME not TODO --- libempathy/empathy-tp-chat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libempathy/empathy-tp-chat.c') diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 1df1cf8a9..8327c4f26 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -921,9 +921,9 @@ tp_chat_group_members_changed_cb (TpChannel *self, if (actor != 0) { actor_contact = chat_lookup_contact (chat, actor, FALSE); if (actor_contact == NULL) { - /* TODO: handle this a tad more gracefully: perhaps the - * actor was a server op. We could use the contact-ids - * detail of MembersChangedDetailed. + /* FIXME: handle this a tad more gracefully: perhaps + * the actor was a server op. We could use the + * contact-ids detail of MembersChangedDetailed. */ DEBUG ("actor %u not a channel member", actor); } -- cgit v1.2.3 From fdbb5ae44e2b82a36f7103b63e5c8a2041faea6c Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 18 Jun 2009 21:29:31 +0100 Subject: Style: avoid marching off the right margin --- libempathy/empathy-tp-chat.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'libempathy/empathy-tp-chat.c') diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 8327c4f26..6810476d1 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -886,17 +886,18 @@ chat_lookup_contact (EmpathyTpChat *chat, for (l = priv->members; l; l = l->next) { EmpathyContact *c = l->data; - if (empathy_contact_get_handle (c) == handle) { - if (remove) { - /* Caller takes the reference. */ - priv->members = g_list_delete_link ( - priv->members, l); - } else { - g_object_ref (c); - } + if (empathy_contact_get_handle (c) != handle) { + continue; + } - return c; + if (remove) { + /* Caller takes the reference. */ + priv->members = g_list_delete_link (priv->members, l); + } else { + g_object_ref (c); } + + return c; } return NULL; -- cgit v1.2.3