[geary/wip/135-contact-popovers: 11/26] Lookup and use Folks individuals in client contact classes
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/135-contact-popovers: 11/26] Lookup and use Folks individuals in client contact classes
- Date: Mon, 8 Apr 2019 00:27:54 +0000 (UTC)
commit 5a68152acae1fe5e21a28de9fe6a470d1d5ac4cf
Author: Michael Gratton <mike vee net>
Date: Fri Mar 15 09:00:52 2019 +1100
Lookup and use Folks individuals in client contact classes
.../application/application-contact-store.vala | 51 ++++++++++++++++++++--
src/client/application/application-contact.vala | 28 ++++++++----
src/client/application/geary-controller.vala | 14 +++---
3 files changed, 74 insertions(+), 19 deletions(-)
---
diff --git a/src/client/application/application-contact-store.vala
b/src/client/application/application-contact-store.vala
index c6df7b76..44753ea3 100644
--- a/src/client/application/application-contact-store.vala
+++ b/src/client/application/application-contact-store.vala
@@ -11,16 +11,20 @@
* This class aggregates data from for both the Engine and Folks,
* allowing contacts for a specific account to be queried.
*/
-public class Application.ContactStore {
+public class Application.ContactStore : Geary.BaseObject {
/** The account this store aggregates data for. */
public Geary.Account account { get; private set; }
+ private Folks.IndividualAggregator individuals;
+
/** Constructs a new contact store for an account. */
- public ContactStore(Geary.Account account) {
+ public ContactStore(Geary.Account account,
+ Folks.IndividualAggregator individuals) {
this.account = account;
+ this.individuals = individuals;
}
/**
@@ -31,10 +35,49 @@ public class Application.ContactStore {
* returned, so if no matching contact already exists a new,
* non-persistent contact will be returned.
*/
- public Contact get(Geary.RFC822.MailboxAddress mailbox) {
+ public async Contact load(Geary.RFC822.MailboxAddress mailbox,
+ GLib.Cancellable? cancellable)
+ throws GLib.Error {
+ Folks.Individual? individual = yield search_match(
+ mailbox.address, cancellable
+ );
Geary.Contact? contact =
this.account.get_contact_store().get_by_rfc822(mailbox);
- return new Contact(this, contact, mailbox);
+ return new Contact(this, individual, contact, mailbox);
+ }
+
+ private async Folks.Individual? search_match(string address,
+ GLib.Cancellable cancellable)
+ throws GLib.Error {
+ if (cancellable.is_cancelled()) {
+ throw new GLib.IOError.CANCELLED("Contact load was cancelled");
+ }
+
+ Folks.SearchView view = new Folks.SearchView(
+ this.individuals,
+ new Folks.SimpleQuery(
+ address,
+ new string[] {
+ Folks.PersonaStore.detail_key(
+ Folks.PersonaDetail.EMAIL_ADDRESSES
+ )
+ }
+ )
+ );
+
+ yield view.prepare();
+
+ Folks.Individual? match = null;
+ if (!view.individuals.is_empty) {
+ match = view.individuals.first();
+ }
+
+ try {
+ yield view.unprepare();
+ } catch (GLib.Error err) {
+ warning("Error unpreparing Folks search: %s", err.message);
+ }
+ return match;
}
}
diff --git a/src/client/application/application-contact.vala b/src/client/application/application-contact.vala
index c325a062..516a8234 100644
--- a/src/client/application/application-contact.vala
+++ b/src/client/application/application-contact.vala
@@ -13,39 +13,51 @@
* queried. Contacts are obtained from the {@link ContactStore} for an
* account.
*/
-public class Application.Contact {
+public class Application.Contact : Geary.BaseObject {
/** The human-readable name of the contact. */
public string display_name { get; private set; }
- /** Determines if {@link display_name} is trusted by the user. */
- public bool display_name_is_trusted { get; private set; default = false; }
-
/** Determines if {@link display_name} the same as its email address. */
public bool display_name_is_email { get; private set; default = false; }
- /** Determines if email from this contact should load remote resources. */
+ /** Determines if this contact was loaded from Folks. */
+ public bool is_desktop_contact { get; private set; default = false; }
+
+ /**
+ * Determines if email from this contact should load remote resources.
+ *
+ * Will automatically load resources from contacts in the desktop
+ * database, or if the Engine's contact has been flagged to do so.
+ */
public bool load_remote_resources {
get {
return (
- this.contact != null &&
- this.contact.contact_flags.always_load_remote_images()
+ this.individual != null ||
+ (this.contact != null &&
+ this.contact.always_load_remote_images())
);
}
}
private weak ContactStore store;
+ private Folks.Individual? individual;
private Geary.Contact? contact;
internal Contact(ContactStore store,
+ Folks.Individual? individual,
Geary.Contact? contact,
Geary.RFC822.MailboxAddress source) {
this.store = store;
+ this.individual = individual;
this.contact = contact;
- if (contact != null) {
+ if (individual != null) {
+ this.display_name = individual.display_name;
+ this.is_desktop_contact = true;
+ } else if (contact != null) {
this.display_name = contact.real_name;
} else {
this.display_name = source.name;
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index c0b337e1..90b55aa2 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -140,6 +140,7 @@ public class GearyController : Geary.BaseObject {
// when closed.
private GLib.Cancellable? open_cancellable = null;
+ private Folks.IndividualAggregator? folks = null;
private Geary.Folder? current_folder = null;
private Cancellable cancellable_folder = new Cancellable();
private Cancellable cancellable_search = new Cancellable();
@@ -267,21 +268,20 @@ public class GearyController : Geary.BaseObject {
error("Error loading web resources: %s", err.message);
}
- Folks.IndividualAggregator individuals =
- Folks.IndividualAggregator.dup();
- if (!individuals.is_prepared) {
+ this.folks = Folks.IndividualAggregator.dup();
+ if (!this.folks.is_prepared) {
// Do this in the background since it can take a long time
// on some systems and the GUI shouldn't be blocked by it
- individuals.prepare.begin((obj, res) => {
+ this.folks.prepare.begin((obj, res) => {
try {
- individuals.prepare.end(res);
+ this.folks.prepare.end(res);
} catch (GLib.Error err) {
warning("Error preparing Folks: %s", err.message);
}
});
}
- this.avatars = new Application.AvatarStore(individuals);
+ this.avatars = new Application.AvatarStore(this.folks);
// Create the main window (must be done after creating actions.)
main_window = new MainWindow(this.application);
@@ -915,7 +915,7 @@ public class GearyController : Geary.BaseObject {
AccountContext context = new AccountContext(
account,
new Geary.App.EmailStore(account),
- new Application.ContactStore(account)
+ new Application.ContactStore(account, this.folks)
);
// XXX Need to set this early since
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]