[empathy] pass handles to add_to_members instead of contact objects
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy] pass handles to add_to_members instead of contact objects
- Date: Wed, 31 Mar 2010 08:41:52 +0000 (UTC)
commit 9a36a55fb92e7f0a0c92a9c04c4d02215af7a4b6
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Mon Dec 14 11:56:34 2009 +0000
pass handles to add_to_members instead of contact objects
libempathy/empathy-tp-contact-list.c | 75 +++++++++++++++++++---------------
1 files changed, 42 insertions(+), 33 deletions(-)
---
diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c
index 9507f5a..b458e1d 100644
--- a/libempathy/empathy-tp-contact-list.c
+++ b/libempathy/empathy-tp-contact-list.c
@@ -373,45 +373,64 @@ tp_contact_list_group_add (EmpathyTpContactList *list,
}
static void
-add_to_members (EmpathyTpContactList *list,
- EmpathyContact *contact)
+got_added_members_cb (EmpathyTpContactFactory *factory,
+ guint n_contacts,
+ EmpathyContact * const * contacts,
+ guint n_failed,
+ const TpHandle *failed,
+ const GError *error,
+ gpointer user_data,
+ GObject *list)
{
EmpathyTpContactListPriv *priv = GET_PRIV (list);
- TpHandle handle;
+ guint i;
- handle = empathy_contact_get_handle (contact);
- if (g_hash_table_lookup (priv->members, GUINT_TO_POINTER (handle)))
+ if (error) {
+ DEBUG ("Error: %s", error->message);
return;
+ }
+
+ for (i = 0; i < n_contacts; i++) {
+ EmpathyContact *contact = contacts[i];
+ TpHandle handle = empathy_contact_get_handle (contact);
/* Add to the list and emit signal */
- g_hash_table_insert (priv->members, GUINT_TO_POINTER (handle),
+ g_hash_table_insert (priv->members, GUINT_TO_POINTER (handle),
g_object_ref (contact));
- g_signal_emit_by_name (list, "members-changed", contact,
+ g_signal_emit_by_name (list, "members-changed", contact,
0, 0, NULL, TRUE);
+ }
}
static void
-tp_contact_list_got_added_members_cb (EmpathyTpContactFactory *factory,
- guint n_contacts,
- EmpathyContact * const * contacts,
- guint n_failed,
- const TpHandle *failed,
- const GError *error,
- gpointer user_data,
- GObject *list)
+add_to_members (EmpathyTpContactList *list,
+ GArray *handles)
{
+ EmpathyTpContactListPriv *priv = GET_PRIV (list);
+ GArray *request;
guint i;
- if (error) {
- DEBUG ("Error: %s", error->message);
+ if (handles->len == 0)
return;
- }
- for (i = 0; i < n_contacts; i++) {
- EmpathyContact *contact = contacts[i];
+ request = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+
+ for (i = 0; i < handles->len; i++) {
+ TpHandle handle = g_array_index (handles, TpHandle, i);
+
+ if (g_hash_table_lookup (priv->members, GUINT_TO_POINTER (handle)))
+ continue;
- add_to_members (EMPATHY_TP_CONTACT_LIST (list), contact);
+ g_array_append_val (request, handle);
}
+
+ if (request->len > 0) {
+ empathy_tp_contact_factory_get_from_handles (priv->factory,
+ request->len, (TpHandle *) request->data,
+ got_added_members_cb, NULL, NULL, G_OBJECT (list));
+ }
+
+ g_array_free (request, TRUE);
}
static void
@@ -605,12 +624,7 @@ tp_contact_list_subscribe_group_members_changed_cb (TpChannel *channel,
GArray *accept;
/* We now get the presence of those contacts, add them to members */
- if (added->len > 0) {
- empathy_tp_contact_factory_get_from_handles (priv->factory,
- added->len, (TpHandle *) added->data,
- tp_contact_list_got_added_members_cb, NULL, NULL,
- G_OBJECT (list));
- }
+ add_to_members (list, added);
/* Those contacts refuse to send us their presence, remove from members. */
for (i = 0; i < removed->len; i++) {
@@ -619,12 +633,7 @@ tp_contact_list_subscribe_group_members_changed_cb (TpChannel *channel,
/* We want those contacts in our contact list but we don't get their
* presence yet. Add to members anyway. */
- if (remote_pending->len > 0) {
- empathy_tp_contact_factory_get_from_handles (priv->factory,
- remote_pending->len, (TpHandle *) remote_pending->data,
- tp_contact_list_got_added_members_cb, NULL, NULL,
- G_OBJECT (list));
- }
+ add_to_members (list, remote_pending);
/* Implicitly accept pending request of contacts which are now members. */
accept = g_array_new (FALSE, FALSE, sizeof (TpHandle));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]