summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-08-26 10:55:20 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2011-09-05 18:44:43 +0100
commit29d365c626445bd3f0c30d9cd6a1103cc87c3d96 (patch)
tree70cb309531996f5eb74eb5bd568b1ee83cca9bee
parente3d4b85839b465e160b91ac7b581dabd1097fc6e (diff)
Connection: simplify getting ContactCaps without presence
If we don't have presence for a contact, we do not have any capabilities for them. But we always want to ensure that all contacts are capable of IM. So, currently there is a special-case in the caps-gathering code: if we have no presence, we only call _get_contact_capabilities on the IM factory: its implementation of this virtual method, unlike all others, doesn't care if it's passed a NULL set of caps. Otherwise, if we do have a set of capabilities, we call gabble_connection_build_contact_caps(), which is essentially a foreach over all channel managers, including the IM factory. I think it's neater to avoid the special case, and treat "no presence" as equivalent (for capabilities purposes) to "presence with no caps".
-rw-r--r--src/connection.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/connection.c b/src/connection.c
index 3b208ae9..660a8dd5 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -3022,6 +3022,17 @@ _emit_capabilities_changed (GabbleConnection *conn,
g_hash_table_destroy (hash);
}
+static const GabbleCapabilitySet *
+empty_caps_set (void)
+{
+ static GabbleCapabilitySet *empty = NULL;
+
+ if (G_UNLIKELY (empty == NULL))
+ empty = gabble_capability_set_new ();
+
+ return empty;
+}
+
/**
* gabble_connection_get_handle_contact_capabilities:
*
@@ -3036,7 +3047,6 @@ gabble_connection_get_handle_contact_capabilities (
TpBaseConnection *base_conn = TP_BASE_CONNECTION (self);
GabblePresence *p;
const GabbleCapabilitySet *caps;
- GPtrArray *arr;
if (handle == base_conn->self_handle)
p = self->self_presence;
@@ -3044,20 +3054,11 @@ gabble_connection_get_handle_contact_capabilities (
p = gabble_presence_cache_get (self->presence_cache, handle);
if (p == NULL)
- {
- DEBUG ("don't know %u's presence; assuming text chat caps.", handle);
-
- arr = g_ptr_array_new ();
- gabble_caps_channel_manager_get_contact_capabilities (
- GABBLE_CAPS_CHANNEL_MANAGER (self->priv->im_factory),
- handle, NULL, arr);
-
- return arr;
- }
+ caps = empty_caps_set ();
+ else
+ caps = gabble_presence_peek_caps (p);
- caps = gabble_presence_peek_caps (p);
- arr = gabble_connection_build_contact_caps (self, handle, caps);
- return arr;
+ return gabble_connection_build_contact_caps (self, handle, caps);
}
static void