From ae86141c0460163fbeb2dd8003939acf65d9d17c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 6 Nov 2013 19:37:05 +0000 Subject: [PATCH 11/11] TpBaseContactList: add mandatory is_blocked vfunc This makes the implementation of the former Contacts methods more efficient. --- .../telepathy-glib/telepathy-glib-sections.txt | 1 + telepathy-glib/base-contact-list.c | 54 ++++++++++++++++++---- telepathy-glib/base-contact-list.h | 5 ++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt index a260d01..b7de832 100644 --- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt @@ -5089,6 +5089,7 @@ TP_TYPE_BLOCKABLE_CONTACT_LIST TpBlockableContactListInterface TpBaseContactListBlockContactsWithAbuseFunc tp_base_contact_list_can_block +tp_base_contact_list_is_blocked tp_base_contact_list_dup_blocked_contacts tp_base_contact_list_block_contacts_async tp_base_contact_list_block_contacts_finish diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c index 96dde02..509c02c 100644 --- a/telepathy-glib/base-contact-list.c +++ b/telepathy-glib/base-contact-list.c @@ -378,6 +378,8 @@ G_DEFINE_INTERFACE (TpMutableContactList, tp_mutable_contact_list, /** * TpBlockableContactListInterface: * @parent: the parent interface + * @is_blocked: the implementation of + * tp_base_contact_list_is_blocked(); must always be provided * @dup_blocked_contacts: the implementation of * tp_base_contact_list_dup_blocked_contacts(); must always be provided * @block_contacts_async: the implementation of @@ -687,6 +689,7 @@ tp_base_contact_list_constructed (GObject *object) TP_BLOCKABLE_CONTACT_LIST_GET_INTERFACE (self); g_return_if_fail (iface->can_block != NULL); + g_return_if_fail (iface->is_blocked != NULL); g_return_if_fail (iface->dup_blocked_contacts != NULL); g_return_if_fail ((iface->block_contacts_async != NULL) ^ (iface->block_contacts_with_abuse_async != NULL)); @@ -2143,6 +2146,45 @@ tp_base_contact_list_can_block (TpBaseContactList *self) } /** + * tp_base_contact_list_is_blocked: + * @self: a contact list manager + * @contact: a contact + * + * Return whether @contact is blocked. It is incorrect to call this method + * before tp_base_contact_list_set_list_received() has been called, after + * the connection has disconnected, or on a #TpBaseContactList that does + * not implement %TP_TYPE_BLOCKABLE_CONTACT_LIST. + * + * For implementations of %TP_TYPE_BLOCKABLE_CONTACT_LIST, this is a virtual + * method, implemented using + * #TpBlockableContactListInterface.dup_blocked_contacts. + * It must always be implemented. + * + * The result of this method must always be consistent with the result + * of tp_base_contact_list_dup_blocked_contacts(). It can usually + * use a more efficient implementation that does not require copying + * a handle-set. + * + * Returns: %TRUE if @contact would be in + * tp_base_contact_list_dup_blocked_contacts() + * Since: 0.UNRELEASED + */ +gboolean +tp_base_contact_list_is_blocked (TpBaseContactList *self, + TpHandle contact) +{ + TpBlockableContactListInterface *iface = + TP_BLOCKABLE_CONTACT_LIST_GET_INTERFACE (self); + + g_return_val_if_fail (iface != NULL, FALSE); + g_return_val_if_fail (iface->is_blocked != NULL, FALSE); + g_return_val_if_fail (tp_base_contact_list_get_state (self, NULL) == + TP_CONTACT_LIST_STATE_SUCCESS, FALSE); + + return iface->is_blocked (self, contact); +} + +/** * tp_base_contact_list_dup_blocked_contacts: * @self: a contact list manager * @@ -4201,18 +4243,10 @@ tp_base_contact_list_fill_contact_attributes (TpBaseContactList *self, { if (self->priv->state == TP_CONTACT_LIST_STATE_SUCCESS) { - /* FIXME: this would be more efficient if we had a - * contact_is_blocked() vfunc */ - TpHandleSet *blocked = tp_base_contact_list_dup_blocked_contacts (self); - gboolean is_blocked; - - is_blocked = tp_handle_set_is_member (blocked, contact); - tp_contact_attribute_map_take_sliced_gvalue (attributes, contact, TP_TOKEN_CONNECTION_INTERFACE_CONTACT_BLOCKING1_BLOCKED, - tp_g_value_slice_new_boolean (is_blocked)); - - tp_handle_set_destroy (blocked); + tp_g_value_slice_new_boolean ( + tp_base_contact_list_is_blocked (self, contact))); } /* else just omit the attributes */ diff --git a/telepathy-glib/base-contact-list.h b/telepathy-glib/base-contact-list.h index 1a6486b..e610895 100644 --- a/telepathy-glib/base-contact-list.h +++ b/telepathy-glib/base-contact-list.h @@ -299,6 +299,9 @@ void tp_base_contact_list_contact_blocking_changed ( gboolean tp_base_contact_list_can_block (TpBaseContactList *self); +_TP_AVAILABLE_IN_UNRELEASED +gboolean tp_base_contact_list_is_blocked (TpBaseContactList *self, + TpHandle contact); TpHandleSet *tp_base_contact_list_dup_blocked_contacts ( TpBaseContactList *self); @@ -345,6 +348,8 @@ struct _TpBlockableContactListInterface { /* mandatory to implement */ + gboolean (*is_blocked) (TpBaseContactList *self, + TpHandle contact); TpBaseContactListDupContactsFunc dup_blocked_contacts; /* unblock_contacts_async is mandatory to implement; either -- 1.8.4.2