[telepathy-sofiasip/master] Do not use the alias if it is derived from the handle URI

Mikhail Zabaluev mikhail.zabaluev at nokia.com
Wed Nov 4 02:18:54 PST 2009


If the client sets our URI-derived alias back to ourselves, it's
useless for display name purposes.
---
 src/conn-aliasing.c |   77 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 2504ea3..8c156f5 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -46,6 +46,39 @@ tpsip_connection_get_alias_flags (TpSvcConnectionInterfaceAliasing *iface,
 }
 
 static gchar *
+conn_get_default_alias (TpsipConnection *self,
+                        TpHandleRepoIface *contact_handles,
+                        TpHandle handle)
+{
+  const url_t *url;
+  gchar *alias = NULL;
+
+  /* TODO: create our custom handle repo to be able to get the URL off it.
+   * Then we can reuse the contact_handles parameter */
+  url = tpsip_conn_get_contact_url (self, handle);
+
+  switch (url->url_type)
+    {
+    case url_sip:
+      /* Return the SIP URI stripped down to [user@]host */
+      if (url->url_user != NULL)
+        alias = g_strdup_printf ("%s@%s",
+                                 url->url_user, url->url_host);
+      else
+        alias = g_strdup (url->url_host);
+      break;
+    case url_tel:
+      /* Retrieve the telephone number */
+      alias = g_strdup (url->url_host);
+      break;
+    default:
+      /* Return the handle string as is */
+      alias = g_strdup (tp_handle_inspect (contact_handles, handle));
+    }
+  return alias;
+}
+
+static gchar *
 conn_get_alias (TpsipConnection *self,
                 TpHandleRepoIface *contact_handles,
                 TpHandle handle)
@@ -60,29 +93,7 @@ conn_get_alias (TpsipConnection *self,
     }
 
   if (alias == NULL)
-    {
-      const url_t *url;
-
-      url = tpsip_conn_get_contact_url (self, handle);
-      switch (url->url_type)
-        {
-        case url_sip:
-          /* Return the SIP URI stripped down to [user@]host */
-          if (url->url_user != NULL)
-            alias = g_strdup_printf ("%s@%s",
-                                     url->url_user, url->url_host);
-          else
-            alias = g_strdup (url->url_host);
-          break;
-        case url_tel:
-          /* Retrieve the telephone number */
-          alias = g_strdup (url->url_host);
-          break;
-        default:
-          /* Return the handle string as is */
-          alias = g_strdup (tp_handle_inspect (contact_handles, handle));
-        }
-    }
+    alias = conn_get_default_alias (self, contact_handles, handle);
 
   g_assert (alias != NULL);
   DEBUG("handle %u got alias %s", handle, alias);
@@ -237,7 +248,9 @@ tpsip_connection_set_aliases (TpSvcConnectionInterfaceAliasing *iface,
 {
   TpsipConnection *self = TPSIP_CONNECTION (iface);
   TpBaseConnection *base = (TpBaseConnection *) self;
+  TpHandleRepoIface *contact_handles;
   const gchar *alias;
+  gchar *default_alias;
   gchar *to_free = NULL;
 
   TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context);
@@ -256,11 +269,25 @@ tpsip_connection_set_aliases (TpSvcConnectionInterfaceAliasing *iface,
 
   alias = collapse_whitespace (alias, &to_free);
 
-  DEBUG("setting alias for self: %s", alias);
-  g_object_set (self, "alias", alias, NULL);
+  contact_handles = tp_base_connection_get_handles (base,
+      TP_HANDLE_TYPE_CONTACT);
+  default_alias = conn_get_default_alias (self,
+      contact_handles, base->self_handle);
+
+  if (strcmp (alias, default_alias) == 0)
+    {
+      DEBUG("using default alias for self");
+      g_object_set (self, "alias", NULL, NULL);
+    }
+  else
+    {
+      DEBUG("setting alias for self: %s", alias);
+      g_object_set (self, "alias", alias, NULL);
+    }
 
   emit_self_alias_change (self, alias);
 
+  g_free (default_alias);
   g_free (to_free);
 
   tp_svc_connection_interface_aliasing_return_from_set_aliases (context);
-- 
1.5.6.5




More information about the telepathy-commits mailing list