diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-06-21 12:25:05 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-06-21 12:32:35 +0100 |
commit | 6df83a17ff312dc3ad99c79bb40163eba687449c (patch) | |
tree | fac7a42de7434ed05b16efef63e2d38830f2774c /src/conn-aliasing.c | |
parent | 7a221f03f2a8796895bd48febe1b04168d1b5a1a (diff) |
Look for better aliases if roster says name=jid.
When we discover that a contact doesn't have an alias at all, we fall
back to their JID, and write this to the roster (as we do for any other
alias we use, to spare our users' precious bandwidth).
This is fine and all, but it means that we ignore any subsequent updates
from the contact to say that they have a better alias. For instance, we
might get a PEP nickname update, or fetch their vCard for some other
reason (getting an avatar, ContactInfo, &c &c). In those cases, we would
like to have any better alias obtained passively to replace the JID
fallback. This is only ever passive: we still don't query for a better
alias if the roster says it's the JID. (Clever users can set the alias
to the empty string, which has the effect of forcing a refresh.)
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=27361
Diffstat (limited to 'src/conn-aliasing.c')
-rw-r--r-- | src/conn-aliasing.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c index 46bc80e3e..782fb82cf 100644 --- a/src/conn-aliasing.c +++ b/src/conn-aliasing.c @@ -880,14 +880,35 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn, GabblePresence *pres; const gchar *tmp, *jid; gchar *resource = NULL; + gboolean roster_alias_was_jid = FALSE; g_return_val_if_fail (NULL != conn, GABBLE_CONNECTION_ALIAS_NONE); g_return_val_if_fail (GABBLE_IS_CONNECTION (conn), GABBLE_CONNECTION_ALIAS_NONE); g_return_val_if_fail (tp_handle_is_valid (contact_handles, handle, NULL), GABBLE_CONNECTION_ALIAS_NONE); + jid = tp_handle_inspect (contact_handles, handle); + g_assert (NULL != jid); + tmp = gabble_roster_handle_get_name (conn->roster, handle); - if (!tp_str_empty (tmp)) + if (!tp_strdiff (tmp, jid)) + { + /* Normally, we prefer whatever we've cached on the roster, to avoid + * wasting bandwidth checking for aliases by repeatedly fetching the + * vCard, and (more importantly) to prefer anything the local user set + * over what the contact says their name is. + * + * However, if the alias stored on the roster is just the contact's JID, + * we check for better aliases that we happen to have received from other + * sources (maybe a PEP nick update, or a vCard we've fetched for the + * avatar, or whatever). If we can't find anything better, we'll use the + * JID, and still say that it came from the roster: this means we don't + * defeat negative caching for contacts who genuinely don't have an + * alias. + */ + roster_alias_was_jid = TRUE; + } + else if (!tp_str_empty (tmp)) { maybe_set (alias, tmp); return GABBLE_CONNECTION_ALIAS_FROM_ROSTER; @@ -925,10 +946,6 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn, } } - jid = tp_handle_inspect (contact_handles, handle); - g_assert (NULL != jid); - - /* MUC handles have the nickname in the resource */ if (gabble_decode_jid (jid, NULL, NULL, &resource) && NULL != resource) @@ -949,9 +966,11 @@ _gabble_connection_get_cached_alias (GabbleConnection *conn, } } - /* otherwise just take their jid */ + /* otherwise just take their jid, which may have been specified on the roster + * as the contact's alias. */ maybe_set (alias, jid); - return GABBLE_CONNECTION_ALIAS_FROM_JID; + return roster_alias_was_jid ? GABBLE_CONNECTION_ALIAS_FROM_ROSTER + : GABBLE_CONNECTION_ALIAS_FROM_JID; } static void |