summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-10-19 15:14:27 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-11-01 12:04:51 (GMT)
commitc712fb46c5ed09a461a86d52a712a03d33beae2d (patch)
tree1bc55806133e22717a7805b6c3ea7fa8517ef6a7
parent1b48e12c7ce5104d4266c6917f32add72aba427b (diff)
downloadtelepathy-glib-c712fb46c5ed09a461a86d52a712a03d33beae2d.tar.gz
telepathy-glib-c712fb46c5ed09a461a86d52a712a03d33beae2d.tar.xz
add contact operations for blocking API
https://bugs.freedesktop.org/show_bug.cgi?id=41801
-rw-r--r--docs/reference/telepathy-glib-sections.txt4
-rw-r--r--telepathy-glib/contact-operations.c119
-rw-r--r--telepathy-glib/contact-operations.h17
-rw-r--r--tests/dbus/contact-list-clt.c59
4 files changed, 193 insertions, 6 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 92764ef..79d1b09 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -4386,6 +4386,10 @@ tp_contact_add_to_group_async
tp_contact_add_to_group_finish
tp_contact_remove_from_group_async
tp_contact_remove_from_group_finish
+tp_contact_block_async
+tp_contact_block_finish
+tp_contact_unblock_async
+tp_contact_unblock_finish
<SUBSECTION Standard>
tp_contact_feature_get_type
tp_contact_get_type
diff --git a/telepathy-glib/contact-operations.c b/telepathy-glib/contact-operations.c
index 1852f33..fcc10ce 100644
--- a/telepathy-glib/contact-operations.c
+++ b/telepathy-glib/contact-operations.c
@@ -371,3 +371,122 @@ tp_contact_remove_from_group_finish (TpContact *self,
{
generic_finish (remove_from_group);
}
+
+/* ContactBlocking */
+
+/**
+ * tp_contact_block_async:
+ * @self: a #TpContact
+ * @report_abusive: if %TRUE, in addition to blocking, report these contacts as
+ * abusive to the server administrators, if supported, see
+ * #TpConnection:can-report-abusive
+ * @callback: a callback to call when the operation finishes
+ * @user_data: data to pass to @callback
+ *
+ * Block communications with a contact, optionally reporting the contact as
+ * abusive to the server administrators. To block more than one contact at once,
+ * see tp_connection_block_contacts_async().
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_contact_block_async (TpContact *self,
+ gboolean report_abusive,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ TpHandle handle;
+ GArray *handles;
+
+ g_return_if_fail (TP_IS_CONTACT (self));
+
+ handle = tp_contact_get_handle (self);
+ handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+ g_array_append_val (handles, handle);
+
+ result = g_simple_async_result_new ((GObject *) self, callback, user_data,
+ tp_contact_block_async);
+
+ tp_cli_connection_interface_contact_blocking_call_block_contacts (
+ tp_contact_get_connection (self), -1,
+ handles, report_abusive, generic_callback, result, g_object_unref, NULL);
+
+ g_array_unref (handles);
+}
+
+/**
+ * tp_contact_block_finish:
+ * @self: a #TpContact
+ * @result: a #GAsyncResult
+ * @error: a #GError to fill
+ *
+ * Finishes tp_contact_block_async()
+ *
+ * Returns: %TRUE if the operation was successful, otherwise %FALSE.
+ *
+ * Since: 0.UNRELEASED
+ */
+gboolean
+tp_contact_block_finish (TpContact *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ generic_finish (block);
+}
+
+/**
+ * tp_contact_unblock_async:
+ * @self: a #TpContact
+ * @callback: a callback to call when the operation finishes
+ * @user_data: data to pass to @callback
+ *
+ * Unblock communications with a contact. To unblock more than one contact
+ * at once, see tp_connection_unblock_contacts_async().
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_contact_unblock_async (TpContact *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ TpHandle handle;
+ GArray *handles;
+
+ g_return_if_fail (TP_IS_CONTACT (self));
+
+ handle = tp_contact_get_handle (self);
+ handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+ g_array_append_val (handles, handle);
+
+ result = g_simple_async_result_new ((GObject *) self, callback, user_data,
+ tp_contact_unblock_async);
+
+ tp_cli_connection_interface_contact_blocking_call_unblock_contacts (
+ tp_contact_get_connection (self), -1,
+ handles, generic_callback, result, g_object_unref, NULL);
+
+ g_array_unref (handles);
+}
+
+/**
+ * tp_contact_unblock_finish:
+ * @self: a #TpContact
+ * @result: a #GAsyncResult
+ * @error: a #GError to fill
+ *
+ * Finishes tp_contact_unblock_async()
+ *
+ * Returns: %TRUE if the operation was successful, otherwise %FALSE.
+ *
+ * Since: 0.UNRELEASED
+ */
+gboolean
+tp_contact_unblock_finish (TpContact *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ generic_finish (unblock);
+}
diff --git a/telepathy-glib/contact-operations.h b/telepathy-glib/contact-operations.h
index 29d483a..82811ac 100644
--- a/telepathy-glib/contact-operations.h
+++ b/telepathy-glib/contact-operations.h
@@ -76,6 +76,23 @@ gboolean tp_contact_remove_from_group_finish (TpContact *self,
GAsyncResult *result,
GError **error);
+/* ContactBlocking */
+
+void tp_contact_block_async (TpContact *self,
+ gboolean report_abusive,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean tp_contact_block_finish (TpContact *self,
+ GAsyncResult *result,
+ GError **error);
+
+void tp_contact_unblock_async (TpContact *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean tp_contact_unblock_finish (TpContact *self,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#endif
diff --git a/tests/dbus/contact-list-clt.c b/tests/dbus/contact-list-clt.c
index fbef64c..4e1138a 100644
--- a/tests/dbus/contact-list-clt.c
+++ b/tests/dbus/contact-list-clt.c
@@ -129,6 +129,36 @@ unblock_contacts_cb (GObject *source,
}
static void
+contact_block_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Test *test = user_data;
+
+ tp_contact_block_finish (TP_CONTACT (source), result, &test->error);
+ g_assert_no_error (test->error);
+
+ test->wait--;
+ if (test->wait <= 0)
+ g_main_loop_quit (test->mainloop);
+}
+
+static void
+contact_unblock_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Test *test = user_data;
+
+ tp_contact_unblock_finish (TP_CONTACT (source), result, &test->error);
+ g_assert_no_error (test->error);
+
+ test->wait--;
+ if (test->wait <= 0)
+ g_main_loop_quit (test->mainloop);
+}
+
+static void
test_block_unblock (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
@@ -243,6 +273,7 @@ test_blocked_contacts (Test *test,
GPtrArray *blocked;
TpHandle handle;
TpContact *alice;
+ gboolean use_contact_api = GPOINTER_TO_UINT (data);
/* Feature is not prepared yet */
g_object_get (test->connection, "blocked-contacts", &blocked, NULL);
@@ -279,8 +310,15 @@ test_blocked_contacts (Test *test,
g_signal_connect (test->connection, "blocked-contacts-changed",
G_CALLBACK (blocked_contacts_changed_cb), test);
- tp_connection_block_contacts_async (test->connection,
- 1, &alice, FALSE, block_contacts_cb, test);
+ if (use_contact_api)
+ {
+ tp_contact_block_async (alice, FALSE, contact_block_cb, test);
+ }
+ else
+ {
+ tp_connection_block_contacts_async (test->connection,
+ 1, &alice, FALSE, block_contacts_cb, test);
+ }
g_object_unref (alice);
@@ -299,8 +337,15 @@ test_blocked_contacts (Test *test,
g_assert_cmpuint (blocked->len, == , 3);
/* Cool, now unblock the poor Alice */
- tp_connection_unblock_contacts_async (test->connection,
- 1, &alice, unblock_contacts_cb, test);
+ if (use_contact_api)
+ {
+ tp_contact_unblock_async (alice, contact_unblock_cb, test);
+ }
+ else
+ {
+ tp_connection_unblock_contacts_async (test->connection,
+ 1, &alice, unblock_contacts_cb, test);
+ }
test->wait = 2;
g_main_loop_run (test->mainloop);
@@ -328,8 +373,10 @@ main (int argc,
test_block_unblock, teardown);
g_test_add ("/contact-list-clt/blocking/can-report-abusive", Test, NULL,
setup, test_can_report_abusive, teardown);
- g_test_add ("/contact-list-clt/blocking/blocked-contacts", Test, NULL,
- setup, test_blocked_contacts, teardown);
+ g_test_add ("/contact-list-clt/blocking/connection/blocked-contacts", Test,
+ GUINT_TO_POINTER (FALSE), setup, test_blocked_contacts, teardown);
+ g_test_add ("/contact-list-clt/blocking/contact/blocked-contacts", Test,
+ GUINT_TO_POINTER (TRUE), setup, test_blocked_contacts, teardown);
return g_test_run ();
}