]> git.0d.be Git - empathy.git/commitdiff
We show in our roster all contacts members and remote-pending of subscribe
authorXavier Claessens <xclaesse@gmail.com>
Thu, 21 Jun 2007 15:19:49 +0000 (15:19 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Thu, 21 Jun 2007 15:19:49 +0000 (15:19 +0000)
2007-06-21 Xavier Claessens  <xclaesse@gmail.com>

* libempathy-gtk/empathy-contact-dialogs.c:
* libempathy-gtk/gossip-contact-list-store.c:
* libempathy-gtk/gossip-contact-list-view.c:
* libempathy/empathy-contact-manager.c:
* libempathy/empathy-tp-contact-list.c:
* libempathy/empathy-contact-list.c:
* libempathy/empathy-contact-list.h:
* libempathy/gossip-contact.c: We show in our roster all contacts
members and remote-pending of subscribe list. Adding/Removing a contact
only add/remove from subscribe list. Accept/Reject a contact in
local-pending of publish list is done using _process_pending().

svn path=/trunk/; revision=164

ChangeLog
libempathy-gtk/empathy-contact-dialogs.c
libempathy-gtk/gossip-contact-list-store.c
libempathy-gtk/gossip-contact-list-view.c
libempathy/empathy-contact-list.c
libempathy/empathy-contact-list.h
libempathy/empathy-contact-manager.c
libempathy/empathy-tp-contact-list.c
libempathy/gossip-contact.c

index b7ef27693c3fd588f7317129b1d504be5210efea..b62a77f0f0ebfa6b9ded15ac159fefd4760de5fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-06-21 Xavier Claessens  <xclaesse@gmail.com>
+
+       * libempathy-gtk/empathy-contact-dialogs.c:
+       * libempathy-gtk/gossip-contact-list-store.c:
+       * libempathy-gtk/gossip-contact-list-view.c:
+       * libempathy/empathy-contact-manager.c:
+       * libempathy/empathy-tp-contact-list.c:
+       * libempathy/empathy-contact-list.c:
+       * libempathy/empathy-contact-list.h:
+       * libempathy/gossip-contact.c: We show in our roster all contacts
+       members and remote-pending of subscribe list. Adding/Removing a contact
+       only add/remove from subscribe list. Accept/Reject a contact in
+       local-pending of publish list is done using _process_pending().
+
 2007-06-15 Xavier Claessens  <xclaesse@gmail.com>
 
        * src/empathy.c:
index 051876940f5fa8ca930717ba4a132e3435222a46..7d1e2603a7808e69b69249f31338fe59f0a1fcab 100644 (file)
@@ -70,14 +70,12 @@ subscription_dialog_response_cb (GtkDialog *dialog,
        contact = empathy_contact_widget_get_contact (contact_widget);
 
        if (response == GTK_RESPONSE_YES) {
-               empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
-                                         contact,
-                                         _("I would like to add you to my contact list."));
+               empathy_contact_list_process_pending (EMPATHY_CONTACT_LIST (manager),
+                                                     contact, TRUE);
        }
        else if (response == GTK_RESPONSE_NO) {
-               empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
-                                            contact,
-                                            _("Sorry, I don't want you in my contact list."));
+               empathy_contact_list_process_pending (EMPATHY_CONTACT_LIST (manager),
+                                                     contact, FALSE);
        }
 
        subscription_dialogs = g_list_remove (subscription_dialogs, dialog);
index 5c8393a1c5c3f8780624d34f7c4abfc69a774732..3db336a72dd643c91abd5d76e2679dc94471ee84 100644 (file)
@@ -410,7 +410,7 @@ gossip_contact_list_store_set_show_offline (GossipContactListStore *store,
                contact = GOSSIP_CONTACT (l->data);
 
                contact_list_store_contact_update (store, contact);
-               
+
                g_object_unref (contact);
        }
        g_list_free (contacts);
index 8b42ab18e4020c5a6ab289dd6257b9646bf7242f..5c3fd274d9703a71c68c1d800e12c2ba9afd8434 100644 (file)
@@ -1387,14 +1387,15 @@ contact_list_view_filter_show_group (GossipContactListView *view,
        contacts = empathy_contact_list_get_members (list);
        for (l = contacts; l && !show_group; l = l->next) {
                if (!gossip_contact_is_in_group (l->data, group)) {
+                       g_object_unref (l->data);
                        continue;
                }
 
                if (contact_list_view_filter_show_contact (l->data, filter)) {
                        show_group = TRUE;
                }
+               g_object_unref (l->data);
        }
-       g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
        g_list_free (contacts);
        g_free (str);
 
index c55d0abf9ca954e4ca89357f5e5b1c6549523f27..3dd398c06403fcf844c197abaa2643182486d47d 100644 (file)
@@ -185,3 +185,17 @@ empathy_contact_list_get_local_pending (EmpathyContactList *list)
        return NULL;
 }
 
+void
+empathy_contact_list_process_pending (EmpathyContactList *list,
+                                     GossipContact      *contact,
+                                     gboolean            accept)
+{
+       g_return_if_fail (EMPATHY_IS_CONTACT_LIST (list));
+
+       if (EMPATHY_CONTACT_LIST_GET_IFACE (list)->process_pending) {
+               EMPATHY_CONTACT_LIST_GET_IFACE (list)->process_pending (list,
+                                                                       contact,
+                                                                       accept);
+       }
+}
+
index 09f54621d616f669b93509e37e813c456870a297..c1f9b41e49c561fa1cc2f8e483a7be3bf66526d9 100644 (file)
@@ -57,6 +57,9 @@ struct _EmpathyContactListIface {
                                              const gchar        *message);
        GList *         (*get_members)       (EmpathyContactList *list);
        GList *         (*get_local_pending) (EmpathyContactList *list);
+       void            (*process_pending)   (EmpathyContactList *list,
+                                             GossipContact      *contact,
+                                             gboolean            accept);
 };
 
 GType                   empathy_contact_list_get_type          (void) G_GNUC_CONST;
@@ -74,6 +77,9 @@ void                    empathy_contact_list_remove            (EmpathyContactLi
                                                                const gchar            *message);
 GList *                 empathy_contact_list_get_members       (EmpathyContactList     *list);
 GList *                 empathy_contact_list_get_local_pending (EmpathyContactList     *list);
+void                    empathy_contact_list_process_pending   (EmpathyContactList     *list,
+                                                               GossipContact          *contact,
+                                                               gboolean                accept);
 
 G_END_DECLS
 
index 5e5f09a43a60136c125eacd7ec60642b286715f2..7f8cdfed5c1bee718277d2e44ae432d3fd37c56e 100644 (file)
@@ -67,6 +67,9 @@ static void           contact_manager_remove               (EmpathyContactList
                                                            const gchar                     *message);
 static GList *        contact_manager_get_members          (EmpathyContactList              *manager);
 static GList *        contact_manager_get_local_pending    (EmpathyContactList              *manager);
+static void           contact_manager_process_pending      (EmpathyContactList              *manager,
+                                                           GossipContact                   *contact,
+                                                           gboolean                         accept);
 static void           contact_manager_setup_foreach        (McAccount                       *account,
                                                            EmpathyTpContactList            *list,
                                                            EmpathyContactManager           *manager);
@@ -129,6 +132,7 @@ contact_manager_iface_init (EmpathyContactListIface *iface)
        iface->remove            = contact_manager_remove;
        iface->get_members       = contact_manager_get_members;
        iface->get_local_pending = contact_manager_get_local_pending;
+       iface->process_pending   = contact_manager_process_pending;
 }
 
 static void
@@ -311,6 +315,28 @@ contact_manager_get_local_pending (EmpathyContactList *manager)
        return pending;
 }
 
+static void
+contact_manager_process_pending (EmpathyContactList *manager,
+                                GossipContact      *contact,
+                                gboolean            accept)
+{
+       EmpathyContactManagerPriv *priv;
+       EmpathyContactList        *list;
+       McAccount                 *account;
+
+       g_return_if_fail (EMPATHY_IS_CONTACT_MANAGER (manager));
+       g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+
+       priv = GET_PRIV (manager);
+
+       account = gossip_contact_get_account (contact);
+       list = g_hash_table_lookup (priv->lists, account);
+
+       if (list) {
+               empathy_contact_list_process_pending (list, contact, accept);
+       }
+}
+
 EmpathyTpContactList *
 empathy_contact_manager_get_list (EmpathyContactManager *manager,
                                  McAccount             *account)
index b696e990cbcfbb79ab34f68dfbdafa7873b12f99..d94eb071e3d4fc7445dd1a70bea32a0e2ff9f396 100644 (file)
@@ -57,6 +57,7 @@ struct _EmpathyTpContactListPriv {
 
        GHashTable           *groups;
        GHashTable           *contacts;
+       GList                *members;
        GList                *local_pending;
 
        DBusGProxy           *aliasing_iface;
@@ -104,6 +105,9 @@ static void                   tp_contact_list_remove                   (EmpathyC
                                                                        const gchar                     *message);
 static GList *                tp_contact_list_get_members              (EmpathyContactList              *list);
 static GList *                tp_contact_list_get_local_pending        (EmpathyContactList              *list);
+static void                   tp_contact_list_process_pending          (EmpathyContactList              *list,
+                                                                       GossipContact                   *contact,
+                                                                       gboolean                         accept);
 static void                   tp_contact_list_remove_local_pending     (EmpathyTpContactList            *list,
                                                                        GossipContact                   *contact);
 static void                   tp_contact_list_contact_removed_foreach  (guint                            handle,
@@ -172,9 +176,6 @@ static void                   tp_contact_list_group_members_removed_cb (GossipTe
                                                                        guint                            reason,
                                                                        const gchar                     *message,
                                                                        EmpathyTpContactList            *list);
-static void                   tp_contact_list_get_members_foreach      (guint                            handle,
-                                                                       GossipContact                   *contact,
-                                                                       GList                          **contacts);
 static void                   tp_contact_list_get_info                 (EmpathyTpContactList            *list,
                                                                        GArray                          *handles);
 static void                   tp_contact_list_request_avatar           (EmpathyTpContactList            *list,
@@ -253,6 +254,7 @@ tp_contact_list_iface_init (EmpathyContactListIface *iface)
        iface->remove            = tp_contact_list_remove;
        iface->get_members       = tp_contact_list_get_members;
        iface->get_local_pending = tp_contact_list_get_local_pending;
+       iface->process_pending   = tp_contact_list_process_pending;
 }
 
 static void
@@ -309,6 +311,9 @@ tp_contact_list_finalize (GObject *object)
        g_list_foreach (priv->local_pending, (GFunc) empathy_contact_list_info_free, NULL);
        g_list_free (priv->local_pending);
 
+       g_list_foreach (priv->members, (GFunc) g_object_unref, NULL);
+       g_list_free (priv->members);
+
        G_OBJECT_CLASS (empathy_tp_contact_list_parent_class)->finalize (object);
 }
 
@@ -471,7 +476,6 @@ tp_contact_list_add (EmpathyContactList *list,
 
        handle = gossip_contact_get_handle (contact);
        gossip_telepathy_group_add_member (priv->subscribe, handle, message);
-       gossip_telepathy_group_add_member (priv->publish, handle, message);
 }
 
 static void
@@ -488,24 +492,19 @@ tp_contact_list_remove (EmpathyContactList *list,
 
        handle = gossip_contact_get_handle (contact);
        gossip_telepathy_group_remove_member (priv->subscribe, handle, message);
-       gossip_telepathy_group_remove_member (priv->publish, handle, message);
 }
 
 static GList *
 tp_contact_list_get_members (EmpathyContactList *list)
 {
        EmpathyTpContactListPriv *priv;
-       GList                    *contacts = NULL;
 
        g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list), NULL);
 
        priv = GET_PRIV (list);
 
-       g_hash_table_foreach (priv->contacts,
-                             (GHFunc) tp_contact_list_get_members_foreach,
-                             &contacts);
-
-       return contacts;
+       g_list_foreach (priv->local_pending, (GFunc) g_object_ref, NULL);
+       return g_list_copy (priv->members);
 }
 
 static GList *
@@ -520,6 +519,27 @@ tp_contact_list_get_local_pending (EmpathyContactList *list)
        return g_list_copy (priv->local_pending);
 }
 
+static void
+tp_contact_list_process_pending (EmpathyContactList *list,
+                                GossipContact      *contact,
+                                gboolean            accept)
+{
+       EmpathyTpContactListPriv *priv;
+       guint                     handle;
+
+       g_return_if_fail (EMPATHY_IS_TP_CONTACT_LIST (list));
+       g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+
+       priv = GET_PRIV (list);
+
+       handle = gossip_contact_get_handle (contact);
+       if (accept) {
+               gossip_telepathy_group_add_member (priv->publish, handle, NULL);
+       } else {
+               gossip_telepathy_group_remove_member (priv->publish, handle, NULL);
+       }
+}
+
 McAccount *
 empathy_tp_contact_list_get_account (EmpathyTpContactList *list)
 {
@@ -964,12 +984,6 @@ tp_contact_list_newchannel_cb (DBusGProxy           *proxy,
                                  G_CALLBACK (tp_contact_list_removed_cb),
                                  list);
 
-               members = gossip_telepathy_group_get_members (group);
-               tp_contact_list_added_cb (group, members, 0,
-                                         TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
-                                         NULL, list);
-               g_array_free (members, TRUE);
-
                if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) {
                        GList *pendings, *l;
 
@@ -1004,14 +1018,36 @@ tp_contact_list_newchannel_cb (DBusGProxy           *proxy,
                                gossip_telepathy_group_info_list_free (pendings);
                        }
                }
-               else if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) {
+               if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) {
+                       GArray *remote_pendings = NULL;
+
                        if (priv->subscribe) {
                                g_object_unref (priv->subscribe);
                        }
                        priv->subscribe = group;
+
+                       /* Makes no sense to be in local-pending */
+                       g_signal_connect (group, "remote-pending",
+                                         G_CALLBACK (tp_contact_list_pending_cb),
+                                         list);
+                       gossip_telepathy_group_get_all_members (group,
+                                                               &members,
+                                                               NULL,
+                                                               &remote_pendings);
+
+                       tp_contact_list_pending_cb (group, remote_pendings, 0,
+                                                   TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
+                                                   NULL,
+                                                   list);
+                       g_array_free (remote_pendings, TRUE);
                } else {
-                       g_assert_not_reached ();
+                       members = gossip_telepathy_group_get_members (group);
                }
+
+               tp_contact_list_added_cb (group, members, 0,
+                                         TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
+                                         NULL, list);
+               g_array_free (members, TRUE);
        }
        else if (handle_type == TP_HANDLE_TYPE_GROUP) {
                const gchar *object_path;
@@ -1105,15 +1141,19 @@ tp_contact_list_added_cb (GossipTelepathyGroup *group,
                }
                else if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) {
                        subscription |= GOSSIP_SUBSCRIPTION_TO;
+                       tp_contact_list_remove_local_pending (list, contact);
                }
 
                tp_contact_list_block_contact (list, contact);
                gossip_contact_set_subscription (contact, subscription);
                tp_contact_list_unblock_contact (list, contact);
 
-               if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) {
-                       tp_contact_list_remove_local_pending (list, contact);
-                       g_signal_emit_by_name (list, "contact-added", contact);
+               if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) {
+                       if (!g_list_find (priv->members, contact)) {
+                               priv->members = g_list_prepend (priv->members,
+                                                               g_object_ref (contact));
+                               g_signal_emit_by_name (list, "contact-added", contact);
+                       }
                }
 
                g_object_unref (contact);
@@ -1155,15 +1195,21 @@ tp_contact_list_removed_cb (GossipTelepathyGroup *group,
                }
                else if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) {
                        subscription &= !GOSSIP_SUBSCRIPTION_TO;
+                       tp_contact_list_remove_local_pending (list, contact);
                }
 
                tp_contact_list_block_contact (list, contact);
                gossip_contact_set_subscription (contact, subscription);
                tp_contact_list_unblock_contact (list, contact);
 
-               if (list_type == TP_CONTACT_LIST_TYPE_PUBLISH) {
-                       tp_contact_list_remove_local_pending (list, contact);
-                       g_signal_emit_by_name (list, "contact-removed", contact);
+               if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) {
+                       GList *l;
+
+                       if ((l = g_list_find (priv->members, contact))) {
+                               g_signal_emit_by_name (list, "contact-removed", contact);
+                               priv->members = g_list_delete_link (priv->members, l);
+                               g_object_unref (contact);
+                       }
                }
                g_object_unref (contact);
        }
@@ -1207,6 +1253,13 @@ tp_contact_list_pending_cb (GossipTelepathyGroup *group,
                        g_signal_emit_by_name (list, "local-pending",
                                               contact, message);
                }
+               else if (list_type == TP_CONTACT_LIST_TYPE_SUBSCRIBE) {
+                       if (!g_list_find (priv->members, contact)) {
+                               priv->members = g_list_prepend (priv->members,
+                                                               g_object_ref (contact));
+                               g_signal_emit_by_name (list, "contact-added", contact);
+                       }
+               }
 
                g_object_unref (contact);
        }
@@ -1519,19 +1572,6 @@ tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
        g_list_free (removed_list);
 }
 
-static void
-tp_contact_list_get_members_foreach (guint           handle,
-                                     GossipContact  *contact,
-                                     GList         **contacts)
-{
-       GossipSubscription subscription;
-
-       subscription = gossip_contact_get_subscription (contact);
-       if (subscription & GOSSIP_SUBSCRIPTION_TO) {
-               *contacts = g_list_append (*contacts, g_object_ref (contact));
-       }
-}
-
 static void
 tp_contact_list_get_info (EmpathyTpContactList *list,
                          GArray               *handles)
index 53fe7e1822acd0c7b780d9cd846e72baf8871636..ba97fa758e99b2c9ea3d8ca13a076c0fe62fd5f5 100644 (file)
@@ -373,7 +373,7 @@ gossip_contact_get_name (GossipContact *contact)
 
        priv = GET_PRIV (contact);
 
-       if (priv->name == NULL) {
+       if (G_STR_EMPTY (priv->name)) {
                return gossip_contact_get_id (contact);
        }
 
@@ -710,7 +710,11 @@ gossip_contact_is_online (GossipContact *contact)
 
        priv = GET_PRIV (contact);
 
-       return (priv->presence != NULL);
+       if (!priv->presence) {
+               return FALSE;
+       }
+
+       return (gossip_presence_get_state (priv->presence) > MC_PRESENCE_OFFLINE);
 }
 
 gboolean