summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-10-24 12:35:14 +0200
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-10-24 12:35:14 +0200
commitde32456d8d460b427ab26c489c142a41319d2023 (patch)
treee3241bd64fa2b70462869d53b767cba530d9cd7b
parentcb67f9f357769b6a6132d4e260e5885f7cdd2bfa (diff)
parentdd159a5d6e737106f0966f2c121953079731f716 (diff)
Merge branch 'telepathy-glib-0.16'
-rw-r--r--telepathy-glib/base-contact-list.c45
-rw-r--r--tests/dbus/contact-lists.c40
2 files changed, 85 insertions, 0 deletions
diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c
index 4f5f3224..a1b4e1f3 100644
--- a/telepathy-glib/base-contact-list.c
+++ b/telepathy-glib/base-contact-list.c
@@ -5783,6 +5783,43 @@ tp_base_contact_list_fill_groups_contact_attributes (GObject *obj,
}
}
+static void
+tp_base_contact_list_fill_blocking_contact_attributes (GObject *obj,
+ const GArray *contacts,
+ GHashTable *attributes_hash)
+{
+ TpBaseContactList *self = _tp_base_connection_find_channel_manager (
+ (TpBaseConnection *) obj, TP_TYPE_BASE_CONTACT_LIST);
+ guint i;
+ TpHandleSet *blocked;
+
+ g_return_if_fail (TP_IS_BASE_CONTACT_LIST (self));
+ g_return_if_fail (TP_IS_BLOCKABLE_CONTACT_LIST (self));
+ g_return_if_fail (self->priv->conn != NULL);
+
+ /* just omit the attributes if the contact list hasn't come in yet */
+ if (self->priv->state != TP_CONTACT_LIST_STATE_SUCCESS)
+ return;
+
+ blocked = tp_base_contact_list_dup_blocked_contacts (self);
+
+ for (i = 0; i < contacts->len; i++)
+ {
+ TpHandle handle;
+ gboolean is_blocked;
+
+ handle = g_array_index (contacts, TpHandle, i);
+
+ is_blocked = tp_handle_set_is_member (blocked, handle);
+
+ tp_contacts_mixin_set_contact_attribute (attributes_hash,
+ handle, TP_TOKEN_CONNECTION_INTERFACE_CONTACT_BLOCKING_BLOCKED,
+ tp_g_value_slice_new_boolean (is_blocked));
+ }
+
+ tp_handle_set_destroy (blocked);
+}
+
/**
* tp_base_contact_list_mixin_groups_iface_init:
* @klass: the service-side D-Bus interface
@@ -6101,6 +6138,14 @@ tp_base_contact_list_mixin_register_with_contacts_mixin (
TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUPS,
tp_base_contact_list_fill_groups_contact_attributes);
}
+
+ if (g_type_is_a (type, TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_BLOCKING)
+ && TP_IS_BLOCKABLE_CONTACT_LIST (self))
+ {
+ tp_contacts_mixin_add_contact_attributes_iface (object,
+ TP_IFACE_CONNECTION_INTERFACE_CONTACT_BLOCKING,
+ tp_base_contact_list_fill_blocking_contact_attributes);
+ }
}
/**
diff --git a/tests/dbus/contact-lists.c b/tests/dbus/contact-lists.c
index 6dce762d..3cedb2fd 100644
--- a/tests/dbus/contact-lists.c
+++ b/tests/dbus/contact-lists.c
@@ -972,6 +972,44 @@ test_contact_list_attrs (Test *test,
}
static void
+test_assert_contact_blocking_attrs (Test *test,
+ TpHandle handle,
+ gboolean expected_blocked)
+{
+ GHashTable *asv;
+ gboolean blocked, valid;
+
+ g_assert_cmpuint (g_hash_table_size (test->contact_attributes), >=, 1);
+ asv = g_hash_table_lookup (test->contact_attributes,
+ GUINT_TO_POINTER (handle));
+ g_assert (asv != NULL);
+ tp_asv_dump (asv);
+
+ blocked = tp_asv_get_boolean (asv,
+ TP_TOKEN_CONNECTION_INTERFACE_CONTACT_BLOCKING_BLOCKED, &valid);
+ g_assert (valid);
+ g_assert (blocked == expected_blocked);
+}
+
+static void
+test_contact_blocking_attrs (Test *test,
+ gconstpointer nil G_GNUC_UNUSED)
+{
+ const gchar * const interfaces[] = {
+ TP_IFACE_CONNECTION_INTERFACE_CONTACT_BLOCKING,
+ NULL };
+ TpHandle handles[] = { test->sjoerd, test->bill };
+
+ tp_connection_get_contact_attributes (test->conn, -1,
+ G_N_ELEMENTS (handles), handles,
+ interfaces, FALSE, contact_attrs_cb, test, test_quit_loop, NULL);
+ g_main_loop_run (test->main_loop);
+
+ test_assert_contact_blocking_attrs (test, test->sjoerd, FALSE);
+ test_assert_contact_blocking_attrs (test, test->bill, TRUE);
+}
+
+static void
test_accept_publish_request (Test *test,
gconstpointer mode)
{
@@ -2641,6 +2679,8 @@ main (int argc,
Test, NULL, setup, test_contacts, teardown);
g_test_add ("/contact-lists/contact-list-attrs",
Test, NULL, setup, test_contact_list_attrs, teardown);
+ g_test_add ("/contact-lists/contact-blocking-attrs",
+ Test, NULL, setup, test_contact_blocking_attrs, teardown);
g_test_add ("/contact-lists/accept-publish-request",
Test, NULL, setup, test_accept_publish_request, teardown);