[folks] Improve the heuristic for choosing an Individual's alias



commit 136b68dab8b4c9be5d9cf8510239835667f6c04a
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Mon Aug 9 17:49:57 2010 +0100

    Improve the heuristic for choosing an Individual's alias
    
    Change the heuristic to choose the first alias which isn't unset or empty,
    and if possible to choose the first alias which isn't equal to the Persona's
    display-id. If all the aliases are equal to display-ids, however, use one
    of them in preference to having no alias at all.

 folks/individual.vala |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/folks/individual.vala b/folks/individual.vala
index a2b0bc4..b95f002 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -432,17 +432,33 @@ public class Folks.Individual : Object,
   private void update_alias ()
     {
       string alias = null;
+      bool alias_is_display_id = false;
 
-      this._personas.foreach ((p) =>
+      foreach (Persona p in this._personas)
         {
           if (p is Alias)
             {
               unowned Alias a = (Alias) p;
 
-              if (alias == null && a.alias != null && a.alias.strip () != "")
-                alias = a.alias;
+              if (a.alias == null || a.alias.strip () == "")
+                continue;
+
+              if (alias == null || alias_is_display_id == true)
+                {
+                  /* We prefer to not have an alias which is the same as the
+                   * Persona's display-id, since having such an alias implies
+                   * that it's the default. However, we prefer using such an
+                   * alias to using the Persona's UID, which is our ultimate
+                   * fallback (below). */
+                  alias = a.alias;
+
+                  if (a.alias == p.display_id)
+                    alias_is_display_id = true;
+                  else if (alias != null)
+                    break;
+                }
             }
-        });
+        }
 
       if (alias == null)
         {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]