summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-10-20 17:49:57 +0200
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-11-01 13:05:05 +0100
commit70df467659e59c11a54245a57dba50eb53f6a8e5 (patch)
tree0cc5c8369b137e0d3d5ad11bbe143d9602d8afdb
parent293c43f3c7d9359d7c03a150dbc348fbeaf14ca6 (diff)
Automatically prepare TP_CONTACT_FEATURE_CONTACT_BLOCKING when possible
Once TP_CONNECTION_FEATURE_CONTACT_BLOCKING has been prepared we can easily prepare TP_CONTACT_FEATURE_CONTACT_BLOCKING on all contacts as we have all the information needed. Extra contact feature for free! https://bugs.freedesktop.org/show_bug.cgi?id=41801
-rw-r--r--telepathy-glib/connection-contact-list.c24
-rw-r--r--telepathy-glib/connection-internal.h3
-rw-r--r--telepathy-glib/connection.c6
-rw-r--r--tests/dbus/contact-list-clt.c72
4 files changed, 83 insertions, 22 deletions
diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c
index 8d8dbbc2..5476d1c5 100644
--- a/telepathy-glib/connection-contact-list.c
+++ b/telepathy-glib/connection-contact-list.c
@@ -1587,6 +1587,18 @@ blocked_changed_item_free (BlockedChangedItem *item)
static void process_queued_blocked_changed (TpConnection *self);
+void
+_tp_connection_set_contact_blocked (TpConnection *self,
+ TpContact *contact)
+{
+ gboolean blocked;
+
+ blocked = tp_g_ptr_array_contains (self->priv->blocked_contacts,
+ contact);
+
+ _tp_contact_set_is_blocked (contact, blocked);
+}
+
static void
blocked_changed_head_ready (TpConnection *self)
{
@@ -1596,6 +1608,18 @@ blocked_changed_head_ready (TpConnection *self)
if (item->result != NULL)
{
+ /* Finish to prepare TP_CONNECTION_FEATURE_CONTACT_BLOCKING, we can
+ * prepare TP_CONTACT_FEATURE_CONTACT_BLOCKING on all contacts as we
+ * have now the list of blocked contacts. */
+ GHashTableIter iter;
+ gpointer contact;
+
+ g_hash_table_iter_init (&iter, self->priv->contacts);
+ while (g_hash_table_iter_next (&iter, NULL, &contact))
+ {
+ _tp_connection_set_contact_blocked (self, contact);
+ }
+
g_simple_async_result_complete (item->result);
}
diff --git a/telepathy-glib/connection-internal.h b/telepathy-glib/connection-internal.h
index 24031cde..e346c2b9 100644
--- a/telepathy-glib/connection-internal.h
+++ b/telepathy-glib/connection-internal.h
@@ -178,6 +178,9 @@ void _tp_connection_prepare_contact_blocking_async (TpProxy *proxy,
GAsyncReadyCallback callback,
gpointer user_data);
+void _tp_connection_set_contact_blocked (TpConnection *self,
+ TpContact *contact);
+
G_END_DECLS
#endif
diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c
index aed21ea1..97011642 100644
--- a/telepathy-glib/connection.c
+++ b/telepathy-glib/connection.c
@@ -3146,6 +3146,12 @@ _tp_connection_add_contact (TpConnection *self,
g_hash_table_insert (self->priv->contacts, GUINT_TO_POINTER (handle),
contact);
+
+ /* Set TP_CONTACT_FEATURE_CONTACT_BLOCKING if possible */
+ if (tp_proxy_is_prepared (self, TP_CONNECTION_FEATURE_CONTACT_BLOCKING))
+ {
+ _tp_connection_set_contact_blocked (self, contact);
+ }
}
diff --git a/tests/dbus/contact-list-clt.c b/tests/dbus/contact-list-clt.c
index 58b03fa6..58434963 100644
--- a/tests/dbus/contact-list-clt.c
+++ b/tests/dbus/contact-list-clt.c
@@ -160,27 +160,32 @@ contact_unblock_cb (GObject *source,
g_main_loop_quit (test->mainloop);
}
-static void
-test_block_unblock (Test *test,
- gconstpointer data G_GNUC_UNUSED)
+static TpContact *
+create_contact (Test *test,
+ const gchar *id)
{
TpHandle handle;
- TpContact *alice, *bob;
- GPtrArray *arr;
+ TpContact *contact;
- /* Create contacts */
- handle = tp_handle_ensure (test->contact_repo, "alice", NULL, &test->error);
+ handle = tp_handle_ensure (test->contact_repo, id, NULL, &test->error);
g_assert_no_error (test->error);
- alice = tp_connection_dup_contact_if_possible (test->connection, handle,
- "alice");
- g_assert (alice != NULL);
+ contact = tp_connection_dup_contact_if_possible (test->connection, handle,
+ id);
+ g_assert (contact != NULL);
- handle = tp_handle_ensure (test->contact_repo, "bob", NULL, &test->error);
- g_assert_no_error (test->error);
+ return contact;
+}
+
+static void
+test_block_unblock (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ TpContact *alice, *bob;
+ GPtrArray *arr;
- bob = tp_connection_dup_contact_if_possible (test->connection, handle, "bob");
- g_assert (bob != NULL);
+ alice = create_contact (test, "alice");
+ bob = create_contact (test, "bob");
arr = g_ptr_array_sized_new (2);
g_ptr_array_add (arr, alice);
@@ -273,10 +278,12 @@ test_blocked_contacts (Test *test,
{
GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_BLOCKING, 0 };
GPtrArray *blocked;
- TpHandle handle;
- TpContact *alice;
+ TpContact *alice, *bill, *guillaume, *sjoerd, *steve;
gboolean use_contact_api = GPOINTER_TO_UINT (data);
+ sjoerd = create_contact (test, "sjoerd@example.com");
+ steve = create_contact (test, "steve@example.com");
+
/* Feature is not prepared yet */
g_object_get (test->connection, "blocked-contacts", &blocked, NULL);
g_assert_cmpuint (blocked->len, == , 0);
@@ -301,13 +308,34 @@ test_blocked_contacts (Test *test,
blocked = tp_connection_get_blocked_contacts (test->connection);
g_assert_cmpuint (blocked->len, == , 2);
- /* Let's block another contact */
- handle = tp_handle_ensure (test->contact_repo, "alice", NULL, &test->error);
- g_assert_no_error (test->error);
+ /* Preparing TP_CONNECTION_FEATURE_CONTACT_BLOCKING gives us
+ * TP_CONTACT_FEATURE_CONTACT_BLOCKING for free. Test that this work with
+ * and and new TpContact. */
+ bill = create_contact (test, "bill@example.com");
+ guillaume = create_contact (test, "guillaume@example.com");
- alice = tp_connection_dup_contact_if_possible (test->connection, handle,
- "alice");
- g_assert (alice != NULL);
+ g_assert (tp_contact_has_feature (sjoerd,
+ TP_CONTACT_FEATURE_CONTACT_BLOCKING));
+ g_assert (!tp_contact_is_blocked (sjoerd));
+
+ g_assert (tp_contact_has_feature (steve,
+ TP_CONTACT_FEATURE_CONTACT_BLOCKING));
+ g_assert (tp_contact_is_blocked (steve));
+
+ g_assert (tp_contact_has_feature (bill, TP_CONTACT_FEATURE_CONTACT_BLOCKING));
+ g_assert (tp_contact_is_blocked (bill));
+
+ g_assert (tp_contact_has_feature (guillaume,
+ TP_CONTACT_FEATURE_CONTACT_BLOCKING));
+ g_assert (!tp_contact_is_blocked (guillaume));
+
+ g_object_unref (steve);
+ g_object_unref (sjoerd);
+ g_object_unref (bill);
+ g_object_unref (guillaume);
+
+ /* Let's block another contact */
+ alice = create_contact (test, "alice");
g_signal_connect (test->connection, "blocked-contacts-changed",
G_CALLBACK (blocked_contacts_changed_cb), test);