summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2022-09-07 11:20:52 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2022-09-08 07:16:50 +0200
commit71eb9d032e7d1d55d62b6836b22368e3d99dbe03 (patch)
treec6eadbefcbc80cd052edd53315eb5b1a4ff5efd1 /src
parente8d6f6ff4dfc8505fbee9c841b85d2446e08ff2c (diff)
downloadgnome-contacts-71eb9d032e7d1d55d62b6836b22368e3d99dbe03.tar.gz
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".
Diffstat (limited to 'src')
-rw-r--r--src/contacts-contact-pane.vala2
-rw-r--r--src/contacts-store.vala36
-rw-r--r--src/contacts-utils.vala36
3 files changed, 37 insertions, 37 deletions
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 486aa30..ffdcbf3 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 92eae91..6a39240 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 64ab16d..f261be9 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);
}