[telepathy-gabble/master] Make GetAliases etc fall back to the full JID
Will Thompson
will.thompson at collabora.co.uk
Sat Apr 25 03:27:16 PDT 2009
Previously, Gabble fell back to the local part of the JID; if the
contact is foo at bar.com, it would default their alias to "foo". But this
is in violation of the spec, which says CMs should "[fall] back on the
handle name if [no alias] is present".
Gabble's old behaviour was slightly nicer on UIs that just want to show
something to the user, but make it impossible for UIs to tell whether a
contact actually has an alias or not. The real fix here is to separate
aliases into petnames and nicknames, but for now this makes Gabble
spec-compliant.
---
src/conn-aliasing.c | 27 +++++++++---------------
src/muc-channel.c | 15 +++++++++++++-
tests/twisted/vcard/test-alias-empty-vcard.py | 4 +-
tests/twisted/vcard/test-vcard-cache.py | 4 +-
4 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index ae5ff09..297e4e1 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -784,8 +784,8 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
TP_HANDLE_TYPE_CONTACT);
GabbleConnectionAliasSource ret = GABBLE_CONNECTION_ALIAS_NONE;
GabblePresence *pres;
- const gchar *tmp;
- gchar *user = NULL, *resource = NULL;
+ const gchar *tmp, *jid;
+ gchar *resource = NULL;
g_return_val_if_fail (NULL != conn, GABBLE_CONNECTION_ALIAS_NONE);
g_return_val_if_fail (GABBLE_IS_CONNECTION (conn), GABBLE_CONNECTION_ALIAS_NONE);
@@ -849,10 +849,10 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
}
}
- tmp = tp_handle_inspect (contact_handles, handle);
- g_assert (NULL != tmp);
+ jid = tp_handle_inspect (contact_handles, handle);
+ g_assert (NULL != jid);
- gabble_decode_jid (tmp, &user, NULL, &resource);
+ gabble_decode_jid (jid, NULL, NULL, &resource);
/* MUC handles have the nickname in the resource */
if (NULL != resource)
@@ -880,22 +880,15 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn,
goto OUT;
}
- /* otherwise just take their local part */
- if (NULL != user)
- {
- ret = GABBLE_CONNECTION_ALIAS_FROM_JID;
+ /* otherwise just take their jid */
+ ret = GABBLE_CONNECTION_ALIAS_FROM_JID;
- if (NULL != alias)
- {
- *alias = user;
- user = NULL;
- }
+ if (NULL != alias)
+ *alias = g_strdup (jid);
- goto OUT;
- }
+ goto OUT;
OUT:
- g_free (user);
g_free (resource);
return ret;
}
diff --git a/src/muc-channel.c b/src/muc-channel.c
index bb70ca8..8b00ede 100644
--- a/src/muc-channel.c
+++ b/src/muc-channel.c
@@ -673,6 +673,7 @@ create_room_identity (GabbleMucChannel *chan)
TpBaseConnection *conn;
TpHandleRepoIface *contact_repo;
gchar *alias = NULL;
+ GabbleConnectionAliasSource source;
priv = GABBLE_MUC_CHANNEL_GET_PRIVATE (chan);
conn = (TpBaseConnection *) priv->conn;
@@ -680,9 +681,21 @@ create_room_identity (GabbleMucChannel *chan)
g_assert (priv->self_jid == NULL);
- _gabble_connection_get_cached_alias (priv->conn, conn->self_handle, &alias);
+ source = _gabble_connection_get_cached_alias (priv->conn, conn->self_handle,
+ &alias);
g_assert (alias != NULL);
+ if (source == GABBLE_CONNECTION_ALIAS_FROM_JID)
+ {
+ gchar *local_part;
+
+ gabble_decode_jid (alias, &local_part, NULL, NULL);
+ g_assert (local_part != NULL);
+ g_free (alias);
+
+ alias = local_part;
+ }
+
priv->self_jid = g_string_new (priv->jid);
g_string_append_c (priv->self_jid, '/');
g_string_append (priv->self_jid, alias);
diff --git a/tests/twisted/vcard/test-alias-empty-vcard.py b/tests/twisted/vcard/test-alias-empty-vcard.py
index 99d2bb5..2460a14 100644
--- a/tests/twisted/vcard/test-alias-empty-vcard.py
+++ b/tests/twisted/vcard/test-alias-empty-vcard.py
@@ -37,10 +37,10 @@ def test(q, bus, conn, stream):
acknowledge_iq(stream, event.stanza)
q.expect('dbus-return', method='RequestAliases',
- value=([u'bob'],))
+ value=([u'bob at foo.com'],))
# A second request should be satisfied from the cache.
- assert conn.Aliasing.RequestAliases([handle]) == ['bob']
+ assert conn.Aliasing.RequestAliases([handle]) == ['bob at foo.com']
conn.Disconnect()
q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
diff --git a/tests/twisted/vcard/test-vcard-cache.py b/tests/twisted/vcard/test-vcard-cache.py
index 7e407ea..53f8a10 100644
--- a/tests/twisted/vcard/test-vcard-cache.py
+++ b/tests/twisted/vcard/test-vcard-cache.py
@@ -33,8 +33,8 @@ def test(q, bus, conn, stream):
EventPattern('dbus-return', method='RequestAliases'),
EventPattern('dbus-error', method='RequestAvatar'))
- # Default alias is our username
- assert r1.value[0] == ['test']
+ # Default alias is our jid
+ assert r1.value[0] == ['test at localhost']
# We don't have a vCard yet
assert r2.error.args[0] == 'contact vCard has no photo'
--
1.5.6.5
More information about the telepathy-commits
mailing list