From dd159a5d6e737106f0966f2c121953079731f716 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 20 Oct 2011 14:43:47 +0200 Subject: [PATCH] base-contact-list: implement TP_TOKEN_CONNECTION_INTERFACE_CONTACT_BLOCKING_BLOCKED https://bugs.freedesktop.org/show_bug.cgi?id=42049 --- telepathy-glib/base-contact-list.c | 45 ++++++++++++++++++++++++++++++++++++ tests/dbus/contact-lists.c | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 0 deletions(-) diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c index 4f5f322..a1b4e1f 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 6dce762..3cedb2f 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); -- 1.7.4.1