diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-10-17 11:37:29 +0200 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-10-31 17:12:30 +0100 |
commit | b6b7882ef113588583d32bd0a201e00d80ff3f6a (patch) | |
tree | 50c7168cd5dc8c3660c5601b394ea24fd1d3bd49 | |
parent | dd3f97cc9ae7f2770f10164f1ad2c8d4a3a04123 (diff) |
add can-report-abusive property and TP_CONNECTION_FEATURE_CONTACT_BLOCKING
https://bugs.freedesktop.org/show_bug.cgi?id=41801
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 3 | ||||
-rw-r--r-- | telepathy-glib/connection-contact-list.c | 90 | ||||
-rw-r--r-- | telepathy-glib/connection-contact-list.h | 7 | ||||
-rw-r--r-- | telepathy-glib/connection-internal.h | 8 | ||||
-rw-r--r-- | telepathy-glib/connection.c | 32 | ||||
-rw-r--r-- | tests/dbus/contact-list-clt.c | 43 |
6 files changed, 183 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index a3ab164c..d1ab923e 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -3606,6 +3606,7 @@ TP_CONNECTION_FEATURE_CONTACT_INFO TP_CONNECTION_FEATURE_BALANCE TP_CONNECTION_FEATURE_CONTACT_LIST TP_CONNECTION_FEATURE_CONTACT_GROUPS +TP_CONNECTION_FEATURE_CONTACT_BLOCKING tp_connection_run_until_ready TpConnectionWhenReadyCb tp_connection_call_when_ready @@ -3664,6 +3665,7 @@ tp_connection_get_feature_quark_contact_info tp_connection_get_feature_quark_balance tp_connection_get_feature_quark_contact_list tp_connection_get_feature_quark_contact_groups +tp_connection_get_feature_quark_contact_blocking <SUBSECTION avatar-requirements> TP_TYPE_AVATAR_REQUIREMENTS TpAvatarRequirements @@ -3721,6 +3723,7 @@ tp_connection_block_contacts_async tp_connection_block_contacts_finish tp_connection_unblock_contacts_async tp_connection_unblock_contacts_finish +tp_connection_can_report_abusive <SUBSECTION> tp_cli_connection_callback_for_connect tp_cli_connection_call_connect diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c index 8dc7ef5f..707aa6b3 100644 --- a/telepathy-glib/connection-contact-list.c +++ b/telepathy-glib/connection-contact-list.c @@ -1507,3 +1507,93 @@ tp_connection_unblock_contacts_finish (TpConnection *self, { generic_finish (unblock_contacts); } + +/** + * TP_CONNECTION_FEATURE_CONTACT_BLOCKING: + * + * Expands to a call to a function that returns a #GQuark representing the + * "contact-blocking" feature. + * + * When this feature is prepared, the #TpConnection:can-report-abusive and + * #TpConnection:blocked-contacts properties of the Connection have been + * retrieved. The #TpContact objects from #TpConnection:blocked-contacts + * have been prepared with the desired features. See + * tp_connection_dup_contact_list() to get the list of contacts, and + * tp_simple_client_factory_add_contact_features() to define which features + * needs to be prepared on them. + * + * One can ask for a feature to be prepared using the + * tp_proxy_prepare_async() function, and waiting for it to callback. + * + * Since: 0.UNRELEASED + */ + +GQuark +tp_connection_get_feature_quark_contact_blocking (void) +{ + return g_quark_from_static_string ("tp-connection-feature-contact-blocking"); +} + +static void +prepare_contact_blocking_cb (TpProxy *proxy, + GHashTable *properties, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + TpConnection *self = (TpConnection *) proxy; + GSimpleAsyncResult *result = user_data; + gboolean valid; + + if (error != NULL) + { + DEBUG ("Error preparing ContactBlocking properties: %s", error->message); + g_simple_async_result_set_from_error (result, error); + goto out; + } + + self->priv->contact_blocking_capabilities = tp_asv_get_uint32 (properties, + "ContactBlockingCapabilities", &valid); + if (!valid) + { + DEBUG ("Connection %s doesn't have ContactBlockingCapabilities property", + tp_proxy_get_object_path (self)); + } + +out: + g_simple_async_result_complete (result); +} + +void +_tp_connection_prepare_contact_blocking_async (TpProxy *proxy, + const TpProxyFeature *feature, + GAsyncReadyCallback callback, + gpointer user_data) +{ + TpConnection *self = (TpConnection *) proxy; + GSimpleAsyncResult *result; + + result = g_simple_async_result_new ((GObject *) self, callback, user_data, + _tp_connection_prepare_contact_blocking_async); + + tp_cli_dbus_properties_call_get_all (self, -1, + TP_IFACE_CONNECTION_INTERFACE_CONTACT_BLOCKING, + prepare_contact_blocking_cb, result, g_object_unref, NULL); +} + +/** + * tp_connection_can_report_abusive: + * @self: a #TpConnection + * + * <!-- --> + * + * Returns: the value of #TpConnection:can-report-abusive + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_can_report_abusive (TpConnection *self) +{ + return (self->priv->contact_blocking_capabilities & + TP_CONTACT_BLOCKING_CAPABILITY_CAN_REPORT_ABUSIVE) != 0; +} diff --git a/telepathy-glib/connection-contact-list.h b/telepathy-glib/connection-contact-list.h index 48acf440..37e21f83 100644 --- a/telepathy-glib/connection-contact-list.h +++ b/telepathy-glib/connection-contact-list.h @@ -158,6 +158,13 @@ void tp_connection_unblock_contacts_async (TpConnection *self, gboolean tp_connection_unblock_contacts_finish (TpConnection *self, GAsyncResult *result, GError **error); + +#define TP_CONNECTION_FEATURE_CONTACT_BLOCKING \ + (tp_connection_get_feature_quark_contact_blocking ()) +GQuark tp_connection_get_feature_quark_contact_blocking (void) G_GNUC_CONST; + +gboolean tp_connection_can_report_abusive (TpConnection *self); + G_END_DECLS #endif diff --git a/telepathy-glib/connection-internal.h b/telepathy-glib/connection-internal.h index cd9a53f9..164d4ccb 100644 --- a/telepathy-glib/connection-internal.h +++ b/telepathy-glib/connection-internal.h @@ -93,6 +93,9 @@ struct _TpConnectionPrivate { GPtrArray *contact_groups; gboolean groups_fetched; + /* ContactBlocking properies */ + TpContactBlockingCapabilities contact_blocking_capabilities; + TpProxyPendingCall *introspection_call; unsigned ready:1; @@ -165,6 +168,11 @@ void _tp_connection_prepare_contact_groups_async (TpProxy *proxy, gpointer user_data); void _tp_connection_contacts_changed_queue_free (GQueue *queue); +void _tp_connection_prepare_contact_blocking_async (TpProxy *proxy, + const TpProxyFeature *feature, + GAsyncReadyCallback callback, + gpointer user_data); + G_END_DECLS #endif diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index 62f86a8a..f866f238 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -281,6 +281,7 @@ enum PROP_DISJOINT_GROUPS, PROP_GROUP_STORAGE, PROP_CONTACT_GROUPS, + PROP_CAN_REPORT_ABUSIVE, N_PROPS }; @@ -366,6 +367,9 @@ tp_connection_get_property (GObject *object, case PROP_CONTACT_GROUPS: g_value_set_boxed (value, self->priv->contact_groups); break; + case PROP_CAN_REPORT_ABUSIVE: + g_value_set_boolean (value, tp_connection_can_report_abusive (self)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -1591,6 +1595,7 @@ enum { FEAT_BALANCE, FEAT_CONTACT_LIST, FEAT_CONTACT_GROUPS, + FEAT_CONTACT_BLOCKING, N_FEAT }; @@ -1604,6 +1609,7 @@ tp_connection_list_features (TpProxyClass *cls G_GNUC_UNUSED) static GQuark need_balance[2] = {0, 0}; static GQuark need_contact_list[3] = {0, 0, 0}; static GQuark need_contact_groups[2] = {0, 0}; + static GQuark need_contact_blocking[2] = {0, 0}; if (G_LIKELY (features[0].name != 0)) return features; @@ -1647,6 +1653,11 @@ tp_connection_list_features (TpProxyClass *cls G_GNUC_UNUSED) need_contact_groups[0] = TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_GROUPS; features[FEAT_CONTACT_GROUPS].interfaces_needed = need_contact_groups; + features[FEAT_CONTACT_BLOCKING].name = TP_CONNECTION_FEATURE_CONTACT_BLOCKING; + features[FEAT_CONTACT_BLOCKING].prepare_async = _tp_connection_prepare_contact_blocking_async; + need_contact_blocking[0] = TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING; + features[FEAT_CONTACT_BLOCKING].interfaces_needed = need_contact_blocking; + /* assert that the terminator at the end is there */ g_assert (features[N_FEAT].name == 0); @@ -2069,6 +2080,27 @@ tp_connection_class_init (TpConnectionClass *klass) param_spec); /** + * TpConnection:can-report-abusive: + * + * When calling tp_connection_block_contacts_async(), the contacts may be + * reporting as abusive to the server administrators by setting + * report_abusive to %TRUE. + * + * For this property to be valid, you must first call + * tp_proxy_prepare_async() with the feature + * %TP_CONNECTION_FEATURE_CONTACT_BLOCKING. + * + * Since: 0.UNRELEASED + */ + param_spec = g_param_spec_boolean ("can-report-abusive", + "Can report abusive", + "Can report abusive", + FALSE, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_CAN_REPORT_ABUSIVE, + param_spec); + + /** * TpConnection::groups-created: * @self: a #TpConnection * @added: a #GStrv with the names of the new groups. diff --git a/tests/dbus/contact-list-clt.c b/tests/dbus/contact-list-clt.c index a5278153..24c835de 100644 --- a/tests/dbus/contact-list-clt.c +++ b/tests/dbus/contact-list-clt.c @@ -171,6 +171,47 @@ test_block_unblock (Test *test, g_ptr_array_unref (arr); } +static void +proxy_prepare_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + Test *test = user_data; + + tp_proxy_prepare_finish (source, result, &test->error); + + test->wait--; + if (test->wait <= 0) + g_main_loop_quit (test->mainloop); +} + +static void +test_can_report_abusive (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_BLOCKING, 0 }; + gboolean abuse; + + /* Feature is not prepared yet */ + g_object_get (test->connection, "can-report-abusive", &abuse, NULL); + g_assert (!abuse); + g_assert (!tp_connection_can_report_abusive (test->connection)); + + tp_proxy_prepare_async (test->connection, features, + proxy_prepare_cb, test); + + test->wait = 1; + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); + + g_assert (tp_proxy_is_prepared (test->connection, + TP_CONNECTION_FEATURE_CONTACT_BLOCKING)); + + g_object_get (test->connection, "can-report-abusive", &abuse, NULL); + g_assert (abuse); + g_assert (tp_connection_can_report_abusive (test->connection)); +} + int main (int argc, char **argv) @@ -180,6 +221,8 @@ main (int argc, g_test_add ("/contact-list-clt/blocking/block-unblock", Test, NULL, setup, test_block_unblock, teardown); + g_test_add ("/contact-list-clt/blocking/can-report-abusive", Test, NULL, + setup, test_can_report_abusive, teardown); return g_test_run (); } |