aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-tp-contact-list.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-06-21 23:19:49 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-06-21 23:19:49 +0800
commite0617b2fc06f59bfcfbd1f03a4364ba12294e718 (patch)
tree81603b1efcd16b7aa5e45b47a9c902804d2e439d /libempathy/empathy-tp-contact-list.c
parentb59ff7a94fab8dd50fae90d0fcc9c03b2de010ac (diff)
downloadgsoc2013-empathy-e0617b2fc06f59bfcfbd1f03a4364ba12294e718.tar
gsoc2013-empathy-e0617b2fc06f59bfcfbd1f03a4364ba12294e718.tar.gz
gsoc2013-empathy-e0617b2fc06f59bfcfbd1f03a4364ba12294e718.tar.bz2
gsoc2013-empathy-e0617b2fc06f59bfcfbd1f03a4364ba12294e718.tar.lz
gsoc2013-empathy-e0617b2fc06f59bfcfbd1f03a4364ba12294e718.tar.xz
gsoc2013-empathy-e0617b2fc06f59bfcfbd1f03a4364ba12294e718.tar.zst
gsoc2013-empathy-e0617b2fc06f59bfcfbd1f03a4364ba12294e718.zip
We show in our roster all contacts members and remote-pending of subscribe
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
Diffstat (limited to 'libempathy/empathy-tp-contact-list.c')
-rw-r--r--libempathy/empathy-tp-contact-list.c116
1 files changed, 78 insertions, 38 deletions
diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c
index b696e990c..d94eb071e 100644
--- a/libempathy/empathy-tp-contact-list.c
+++ b/libempathy/empathy-tp-contact-list.c
@@ -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);
}
@@ -1520,19 +1573,6 @@ tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
}
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)
{