[gnome-contacts/nielsdg/core-should-stay-core: 9/11] Move link suggestions to Contacts.Store




commit 71eb9d032e7d1d55d62b6836b22368e3d99dbe03
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Wed Sep 7 11:20:52 2022 +0200

    Move link suggestions to Contacts.Store
    
    That way, the Utils namespace doesn't need to know about
    `Contacts.Store` which is not part of "core".

 src/contacts-contact-pane.vala |  2 +-
 src/contacts-store.vala        | 36 ++++++++++++++++++++++++++++++++++++
 src/contacts-utils.vala        | 36 ------------------------------------
 3 files changed, 37 insertions(+), 37 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 486aa30f..ffdcbf33 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -104,7 +104,7 @@ public class Contacts.ContactPane : Adw.Bin {
     if (contact.individual != null) {
       var matches = this.store.aggregator.get_potential_matches (contact.individual, MatchResult.HIGH);
       foreach (var i in matches.keys) {
-        if (i != null && Utils.suggest_link_to (this.store, contact.individual, i)) {
+        if (i != null && this.store.suggest_link_to (contact.individual, i)) {
           add_suggestion (contact.individual, i);
           break;
         }
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 92eae915..6a392404 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -302,4 +302,40 @@ public class Contacts.Store : GLib.Object {
     var settings = new GLib.Settings ("org.freedesktop.folks");
     settings.set_string ("primary-store", "eds:%s".printf (e_store.id));
   }
+
+  public bool suggest_link_to (Individual self, Individual other) {
+    if (non_linkable (self) || non_linkable (other))
+      return false;
+
+    if (!may_suggest_link (self, other))
+      return false;
+
+    /* Only connect main contacts with non-mainable contacts.
+       non-main contacts can link to any other */
+    return !Utils.has_main_persona (self) || !has_mainable_persona (other);
+  }
+
+  // These are "regular" address book contacts, i.e. they contain a
+  // persona that would be "main" if that persona was the primary store
+  private bool has_mainable_persona (Individual individual) {
+    foreach (var p in individual.personas) {
+      if (p.store.type_id == "eds" &&
+          !Utils.persona_is_google_other (p))
+        return true;
+    }
+    return false;
+  }
+
+  // We never want to suggest linking to google contacts that
+  // are part of "Other Contacts"
+  private bool non_linkable (Individual individual) {
+    bool all_unlinkable = true;
+
+    foreach (var p in individual.personas) {
+      if (!Utils.persona_is_google_other (p))
+        all_unlinkable = false;
+    }
+
+    return all_unlinkable;
+  }
 }
diff --git a/src/contacts-utils.vala b/src/contacts-utils.vala
index 64ab16d5..f261be99 100644
--- a/src/contacts-utils.vala
+++ b/src/contacts-utils.vala
@@ -85,18 +85,6 @@ namespace Contacts.Utils {
     return false;
   }
 
-  public bool suggest_link_to (Store store, Individual self, Individual other) {
-    if (non_linkable (self) || non_linkable (other))
-      return false;
-
-    if (!store.may_suggest_link (self, other))
-      return false;
-
-    /* Only connect main contacts with non-mainable contacts.
-       non-main contacts can link to any other */
-    return !has_main_persona (self) || !has_mainable_persona (other);
-  }
-
   /* We claim something is "removable" if at least one persona is removable,
   that will typically unlink the rest. */
   public bool can_remove_personas (Individual individual) {
@@ -140,30 +128,6 @@ namespace Contacts.Utils {
     return store.display_name;
   }
 
-  /* These are "regular" address book contacts, i.e. they contain a
-     persona that would be "main" if that persona was the primary store */
-  private bool has_mainable_persona (Individual individual) {
-    foreach (var p in individual.personas) {
-      if (p.store.type_id == "eds" &&
-          !persona_is_google_other (p))
-        return true;
-    }
-    return false;
-  }
-
-  /* We never want to suggest linking to google contacts that
-     are not My Contacts nor Profiles */
-  private bool non_linkable (Individual individual) {
-    bool all_unlinkable = true;
-
-    foreach (var p in individual.personas) {
-      if (!persona_is_google_other (p))
-        all_unlinkable = false;
-    }
-
-    return all_unlinkable;
-  }
-
   public bool persona_is_google (Persona persona) {
     return persona.store.type_id == "eds" && esource_uid_is_google (persona.store.id);
   }


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