]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-contact-list.c
Replace empathy_connection_get_protocol by tp_connection_parse_object_path
[empathy.git] / libempathy / empathy-tp-contact-list.c
index 051c342c99431f71bbcf1469f85c9afdd4c215a8..6868e84a66d8911603f978a05912813b942bbe13 100644 (file)
@@ -228,7 +228,8 @@ tp_contact_list_group_add_data_unref (gpointer user_data)
 {
        GroupAddData *data = user_data;
 
-       if (--data->ref_count == 0) {
+       data->ref_count--;
+       if (data->ref_count == 0) {
                g_array_free (data->handles, TRUE);
                g_slice_free (GroupAddData, data);
        }
@@ -304,6 +305,7 @@ tp_contact_list_group_request_handles_cb (TpConnection *connection,
                                                list);
 }
 
+/* This function takes ownership of handles array */
 static void
 tp_contact_list_group_add (EmpathyTpContactList *list,
                           const gchar          *group_name,
@@ -314,6 +316,7 @@ tp_contact_list_group_add (EmpathyTpContactList *list,
        const gchar              *names[] = {group_name, NULL};
        GroupAddData             *data;
 
+       /* Search the channel for that group name */
        channel = g_hash_table_lookup (priv->groups, group_name);
        if (channel) {
                tp_cli_channel_interface_group_call_add_members (channel, -1,
@@ -322,6 +325,10 @@ tp_contact_list_group_add (EmpathyTpContactList *list,
                return;
        }
 
+       /* That group does not exist yet, we have to:
+        * 1) Request an handle for the group name
+        * 2) Request a channel
+        * 3) Add handles in members of the new channel */
        data = g_slice_new0 (GroupAddData);
        data->handles = handles;
        data->ref_count = 1;
@@ -334,15 +341,24 @@ tp_contact_list_group_add (EmpathyTpContactList *list,
 
 static void
 tp_contact_list_got_added_members_cb (EmpathyTpContactFactory *factory,
-                                     GList                   *contacts,
+                                     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);
-       GList *l;
+       guint i;
+
+       if (error) {
+               DEBUG ("Error: %s", error->message);
+               return;
+       }
 
-       for (l = contacts; l; l = l->next) {
-               EmpathyContact *contact = l->data;
+       for (i = 0; i < n_contacts; i++) {
+               EmpathyContact *contact = contacts[i];
                TpHandle handle;
 
                handle = empathy_contact_get_handle (contact);
@@ -367,15 +383,24 @@ tp_contact_list_got_added_members_cb (EmpathyTpContactFactory *factory,
 
 static void
 tp_contact_list_got_local_pending_cb (EmpathyTpContactFactory *factory,
-                                     GList                   *contacts,
-                                     gpointer                 info,
+                                     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);
-       GList *l;
+       guint i;
 
-       for (l = contacts; l; l = l->next) {
-               EmpathyContact *contact = l->data;
+       if (error) {
+               DEBUG ("Error: %s", error->message);
+               return;
+       }
+
+       for (i = 0; i < n_contacts; i++) {
+               EmpathyContact *contact = contacts[i];
                TpHandle handle;
                const gchar *message;
                TpChannelGroupChangeReason reason;
@@ -700,7 +725,7 @@ tp_contact_list_constructed (GObject *list)
 {
 
        EmpathyTpContactListPriv *priv = GET_PRIV (list);
-       const gchar              *protocol_name = NULL;
+       gchar                    *protocol_name = NULL;
        const gchar              *names[] = {NULL, NULL};
 
        priv->factory = empathy_tp_contact_factory_dup_singleton (priv->connection);
@@ -735,10 +760,11 @@ tp_contact_list_constructed (GObject *list)
        /* Check for protocols that does not support contact groups. We can
         * put all contacts into a special group in that case.
         * FIXME: Default group should be an information in the profile */
-       //protocol_name = tp_connection_get_protocol (priv->connection);
+       tp_connection_parse_object_path (priv->connection, &protocol_name, NULL);
        if (!tp_strdiff (protocol_name, "local-xmpp")) {
                priv->protocol_group = _("People nearby");
        }
+       g_free (protocol_name);
 }
 
 static void
@@ -807,7 +833,8 @@ empathy_tp_contact_list_init (EmpathyTpContactList *list)
 
        list->priv = priv;
 
-       /* Map group's name to group's channel */
+       /* Map group's name to group's TpChannel. The group name string is owned
+        * by the TpChannel object */
        priv->groups = g_hash_table_new_full (g_str_hash, g_str_equal,
                                              NULL,
                                              (GDestroyNotify) g_object_unref);
@@ -857,6 +884,11 @@ tp_contact_list_add (EmpathyContactList *list,
                tp_cli_channel_interface_group_call_add_members (priv->subscribe,
                        -1, &handles, message, NULL, NULL, NULL, NULL);
        }
+       if (priv->publish &&
+           g_hash_table_lookup (priv->pendings, GUINT_TO_POINTER (handle))) {
+               tp_cli_channel_interface_group_call_add_members (priv->publish,
+                       -1, &handles, message, NULL, NULL, NULL, NULL);
+       }
 }
 
 static void