telepathy-glib: TpContact: do not override properties with attributes we didn't request
Xavier Claessens
xclaesse at kemper.freedesktop.org
Tue Sep 11 03:07:14 PDT 2012
Module: telepathy-glib
Branch: master
Commit: 6555f449c4b6490f08d7b2c8c523faa4c542b89d
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=6555f449c4b6490f08d7b2c8c523faa4c542b89d
Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date: Fri Jun 8 16:28:49 2012 +0200
TpContact: do not override properties with attributes we didn't request
We check wanted flags for everything but States and Groups, there is
no reason for that. Besides, if we did not request those attributes,
there are chances we didn't bind to change notification neither.
---
telepathy-glib/connection-contact-list.c | 5 ++
telepathy-glib/contact.c | 61 ++++++++++++++++-------------
2 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c
index 9e59af2..4d53dfe 100644
--- a/telepathy-glib/connection-contact-list.c
+++ b/telepathy-glib/connection-contact-list.c
@@ -294,6 +294,7 @@ static void
prepare_roster (TpConnection *self,
GSimpleAsyncResult *result)
{
+ TpContactFeature feature_states = TP_CONTACT_FEATURE_SUBSCRIPTION_STATES;
GArray *features;
const gchar **supported_interfaces;
@@ -306,6 +307,10 @@ prepare_roster (TpConnection *self,
features = tp_simple_client_factory_dup_contact_features (
tp_proxy_get_factory (self), self);
+ /* We'll get subscription states for free, but we still need to tell
+ * TpContact to bind to change notification. */
+ g_array_append_val (features, feature_states);
+
supported_interfaces = _tp_contacts_bind_to_signals (self, features->len,
(TpContactFeature *) features->data);
diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c
index ea2c178..988be11 100644
--- a/telepathy-glib/contact.c
+++ b/telepathy-glib/contact.c
@@ -3649,6 +3649,7 @@ tp_contact_set_attributes (TpContact *contact,
const gchar *s;
gpointer boxed;
+ /* Identifier */
s = tp_asv_get_string (asv, TP_TOKEN_CONNECTION_CONTACT_ID);
if (s == NULL)
@@ -3676,7 +3677,7 @@ tp_contact_set_attributes (TpContact *contact,
return FALSE;
}
-
+ /* Alias */
if (wanted & CONTACT_FEATURE_FLAG_ALIAS)
{
s = tp_asv_get_string (asv,
@@ -3697,6 +3698,7 @@ tp_contact_set_attributes (TpContact *contact,
}
}
+ /* Avatar */
if (wanted & CONTACT_FEATURE_FLAG_AVATAR_TOKEN)
{
s = tp_asv_get_string (asv,
@@ -3711,6 +3713,7 @@ tp_contact_set_attributes (TpContact *contact,
contact_maybe_update_avatar_data (contact);
}
+ /* Presence */
if (wanted & CONTACT_FEATURE_FLAG_PRESENCE)
{
boxed = tp_asv_get_boxed (asv,
@@ -3764,34 +3767,38 @@ tp_contact_set_attributes (TpContact *contact,
}
/* ContactList subscription states */
- {
- TpSubscriptionState subscribe;
- TpSubscriptionState publish;
- const gchar *publish_request;
- gboolean subscribe_valid = FALSE;
- gboolean publish_valid = FALSE;
-
- subscribe = tp_asv_get_uint32 (asv,
- TP_TOKEN_CONNECTION_INTERFACE_CONTACT_LIST_SUBSCRIBE,
- &subscribe_valid);
- publish = tp_asv_get_uint32 (asv,
- TP_TOKEN_CONNECTION_INTERFACE_CONTACT_LIST_PUBLISH,
- &publish_valid);
- publish_request = tp_asv_get_string (asv,
- TP_TOKEN_CONNECTION_INTERFACE_CONTACT_LIST_PUBLISH_REQUEST);
-
- if (subscribe_valid && publish_valid)
- {
- contact_set_subscription_states (contact, subscribe, publish,
- publish_request);
- }
- }
+ if (wanted & CONTACT_FEATURE_FLAG_STATES)
+ {
+ TpSubscriptionState subscribe;
+ TpSubscriptionState publish;
+ const gchar *publish_request;
+ gboolean subscribe_valid = FALSE;
+ gboolean publish_valid = FALSE;
+
+ subscribe = tp_asv_get_uint32 (asv,
+ TP_TOKEN_CONNECTION_INTERFACE_CONTACT_LIST_SUBSCRIBE,
+ &subscribe_valid);
+ publish = tp_asv_get_uint32 (asv,
+ TP_TOKEN_CONNECTION_INTERFACE_CONTACT_LIST_PUBLISH,
+ &publish_valid);
+ publish_request = tp_asv_get_string (asv,
+ TP_TOKEN_CONNECTION_INTERFACE_CONTACT_LIST_PUBLISH_REQUEST);
+
+ if (subscribe_valid && publish_valid)
+ {
+ contact_set_subscription_states (contact, subscribe, publish,
+ publish_request);
+ }
+ }
/* ContactGroups */
- boxed = tp_asv_get_boxed (asv,
- TP_TOKEN_CONNECTION_INTERFACE_CONTACT_GROUPS_GROUPS,
- G_TYPE_STRV);
- contact_maybe_set_contact_groups (contact, boxed);
+ if (wanted & CONTACT_FEATURE_FLAG_CONTACT_GROUPS)
+ {
+ boxed = tp_asv_get_boxed (asv,
+ TP_TOKEN_CONNECTION_INTERFACE_CONTACT_GROUPS_GROUPS,
+ G_TYPE_STRV);
+ contact_maybe_set_contact_groups (contact, boxed);
+ }
/* ContactBlocking */
if (wanted & CONTACT_FEATURE_FLAG_CONTACT_BLOCKING)
More information about the telepathy-commits
mailing list