[geary/wip/135-contact-popovers: 13/13] Use contacts in ConversationMessage to display originators/recipients
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/135-contact-popovers: 13/13] Use contacts in ConversationMessage to display originators/recipients
- Date: Thu, 14 Mar 2019 22:18:53 +0000 (UTC)
commit 08db14c88d355c4e90633984ece7c299109cb389
Author: Michael Gratton <mike vee net>
Date: Fri Mar 15 09:01:54 2019 +1100
Use contacts in ConversationMessage to display originators/recipients
Since contact lookup is async, we need to add originators/recipients
asynchronously as well. Do this when loading avatars (that'll amount to
the same thing in the end anyway) and rename the methods to be more
descriptive.
.../conversation-viewer/conversation-email.vala | 13 +-
.../conversation-viewer/conversation-list-box.vala | 8 +-
.../conversation-viewer/conversation-message.vala | 180 +++++++++++----------
3 files changed, 110 insertions(+), 91 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-email.vala
b/src/client/conversation-viewer/conversation-email.vala
index f0d23c2e..64ecdafd 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -559,17 +559,18 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
}
/**
- * Loads the avatar for the primary message.
+ * Loads the contacts for the primary message.
*/
- public async void load_avatar()
+ public async void load_contacts()
throws GLib.Error {
try {
- yield this.primary_message.load_avatar(this.load_cancellable);
+ yield this.primary_message.load_contacts(this.load_cancellable);
} catch (IOError.CANCELLED err) {
// okay
} catch (Error err) {
- Application.Contact? from = this.primary_message.primary_originator;
- debug("Avatar load failed for \"%s\": %s",
+ Geary.RFC822.MailboxAddress? from =
+ this.primary_message.primary_originator;
+ debug("Contact load failed for \"%s\": %s",
from != null ? from.to_string() : "<unknown>", err.message);
}
}
@@ -849,7 +850,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
attached_message.web_view.add_internal_resources(cid_resources);
this.sub_messages.add(attached_message);
this._attached_messages.add(attached_message);
- attached_message.load_avatar.begin(this.load_cancellable);
+ attached_message.load_contacts.begin(this.load_cancellable);
yield attached_message.load_message_body(
sub_message, this.load_cancellable
);
diff --git a/src/client/conversation-viewer/conversation-list-box.vala
b/src/client/conversation-viewer/conversation-list-box.vala
index 7051499b..e0c3980c 100644
--- a/src/client/conversation-viewer/conversation-list-box.vala
+++ b/src/client/conversation-viewer/conversation-list-box.vala
@@ -640,7 +640,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
// Load the interesting row completely up front, and load the
// remaining in the background so we can return fast.
- interesting_row.view.load_avatar.begin();
+ interesting_row.view.load_contacts.begin();
yield interesting_row.expand();
this.finish_loading.begin(
query, uninteresting, post_interesting
@@ -801,7 +801,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
// filling the empty space.
foreach (Geary.Email email in to_append) {
EmailRow row = add_email(email);
- yield row.view.load_avatar();
+ yield row.view.load_contacts();
if (is_interesting(email)) {
yield row.expand();
}
@@ -835,7 +835,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
// Only adjust for the loading row going away once
loading_height = 0;
- yield row.view.load_avatar();
+ yield row.view.load_contacts();
yield throttle_loading();
}
@@ -885,7 +885,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
if (!this.cancellable.is_cancelled()) {
EmailRow row = add_email(full_email);
- yield row.view.load_avatar();
+ yield row.view.load_contacts();
this.search.highlight_row_if_matching(row);
yield row.expand();
}
diff --git a/src/client/conversation-viewer/conversation-message.vala
b/src/client/conversation-viewer/conversation-message.vala
index e8f60f27..71f5b32f 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -174,8 +174,14 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
private static GLib.VariantType MAILBOX_TYPE = new GLib.VariantType("(ss)");
- /** Originator for display name lookup, avatar, and so on. */
- internal Application.Contact? primary_originator {
+
+ /** Contact for the primary originator, if any. */
+ internal Application.Contact? primary_contact {
+ get; private set;
+ }
+
+ /** Mailbox assumed to be the primary sender. */
+ internal Geary.RFC822.MailboxAddress? primary_originator {
get; private set;
}
@@ -190,6 +196,8 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
/** HTML view that displays the message body. */
internal ConversationWebView web_view { get; private set; }
+ private Geary.EmailHeaderSet headers;
+
private Application.ContactStore contacts;
@@ -251,6 +259,8 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
private Gtk.Widget? body_placeholder = null;
+ private string empty_from_label;
+
// The web_view's context menu
private Gtk.Menu? context_menu = null;
@@ -318,15 +328,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
Application.ContactStore contacts,
Configuration config) {
this(
- Util.Email.get_primary_originator(email),
- email.from,
- email.reply_to,
- email.sender,
- email.to,
- email.cc,
- email.bcc,
- email.date,
- email.subject,
+ email,
email.preview != null ? email.preview.buffer.get_valid_utf8() : null,
load_remote_resources,
contacts,
@@ -346,15 +348,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
Application.ContactStore contacts,
Configuration config) {
this(
- Util.Email.get_primary_originator(message),
- message.from,
- message.reply_to,
- message.sender,
- message.to,
- message.cc,
- message.bcc,
- message.date,
- message.subject,
+ message,
message.get_preview(),
load_remote_resources,
contacts,
@@ -362,26 +356,16 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
);
}
- private ConversationMessage(Geary.RFC822.MailboxAddress? primary_originator,
- Geary.RFC822.MailboxAddresses? from,
- Geary.RFC822.MailboxAddresses? reply_to,
- Geary.RFC822.MailboxAddress? sender,
- Geary.RFC822.MailboxAddresses? to,
- Geary.RFC822.MailboxAddresses? cc,
- Geary.RFC822.MailboxAddresses? bcc,
- Geary.RFC822.Date? date,
- Geary.RFC822.Subject? subject,
+ private ConversationMessage(Geary.EmailHeaderSet headers,
string? preview,
bool load_remote_resources,
Application.ContactStore contacts,
Configuration config) {
base_ref();
+ this.headers = headers;
this.load_remote_resources = load_remote_resources;
this.contacts = contacts;
-
- if (primary_originator != null) {
- this.primary_originator = contacts.get(primary_originator);
- }
+ this.primary_originator = Util.Email.get_primary_originator(headers);
// Actions
@@ -437,23 +421,23 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
(MenuModel) builder.get_object("context_menu_inspector");
}
- // Compact headers
+ // Compact headers. These are partially done here and partially
+ // in load_contacts.
// Translators: This is displayed in place of the from address
// when the message has no from address.
- string empty_from = _("No sender");
+ this.empty_from_label = _("No sender");
- this.compact_from.set_text(format_originator_compact(from, empty_from));
this.compact_from.get_style_context().add_class(FROM_CLASS);
string date_text = "";
string date_tooltip = "";
- if (date != null) {
+ if (headers.date != null) {
date_text = Date.pretty_print(
- date.value, config.clock_format
+ headers.date.value, config.clock_format
);
date_tooltip = Date.pretty_print_verbose(
- date.value, config.clock_format
+ headers.date.value, config.clock_format
);
}
this.compact_date.set_text(date_text);
@@ -472,21 +456,17 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
this.compact_body.set_text(clean_preview);
}
- // Full headers
-
- fill_originator_addresses(from, reply_to, sender, empty_from);
+ // Full headers. These are partially done here and partially
+ // in load_contacts.
this.date.set_text(date_text);
this.date.set_tooltip_text(date_tooltip);
+ Geary.RFC822.Subject? subject = headers.subject;
if (subject != null) {
this.subject.set_text(subject.value);
this.subject.set_visible(true);
this.subject_searchable = subject.value.casefold();
}
- fill_header_addresses(this.to_header, to);
- fill_header_addresses(this.cc_header, cc);
- fill_header_addresses(this.bcc_header, bcc);
-
// Web view
@@ -651,27 +631,58 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
/**
- * Starts loading the avatar for the message's sender.
+ * Starts loading message contacts and the avatar.
*/
- public async void load_avatar(GLib.Cancellable cancellable)
+ public async void load_contacts(GLib.Cancellable cancellable)
throws GLib.Error {
MainWindow? main = this.get_toplevel() as MainWindow;
- if (this.primary_originator != null &&
- main != null &&
- !cancellable.is_cancelled()) {
- Application.AvatarStore loader = main.application.controller.avatars;
- int window_scale = get_scale_factor();
- int pixel_size = Application.AvatarStore.PIXEL_SIZE * window_scale;
- Gdk.Pixbuf? avatar_buf = yield loader.load(
- this.primary_originator.primary_mailbox, pixel_size, cancellable
- );
- if (avatar_buf != null) {
- this.avatar.set_from_surface(
- Gdk.cairo_surface_create_from_pixbuf(
- avatar_buf, window_scale, get_window()
- )
+ if (main != null && !cancellable.is_cancelled()) {
+ // Load the primary contact and avatar
+ if (this.primary_originator != null) {
+ this.primary_contact = yield this.contacts.load(
+ this.primary_originator, cancellable
);
+
+ Application.AvatarStore loader = main.application.controller.avatars;
+ int window_scale = get_scale_factor();
+ int pixel_size = Application.AvatarStore.PIXEL_SIZE * window_scale;
+ Gdk.Pixbuf? avatar_buf = yield loader.load(
+ this.primary_originator, pixel_size, cancellable
+ );
+ if (avatar_buf != null) {
+ this.avatar.set_from_surface(
+ Gdk.cairo_surface_create_from_pixbuf(
+ avatar_buf, window_scale, get_window()
+ )
+ );
+ }
+ } else {
+ this.avatar.set_from_icon_name(
+ "avatar-default-symbolic", Gtk.IconSize.DIALOG
+ );
+ this.avatar.set_pixel_size(Application.AvatarStore.PIXEL_SIZE);
}
+
+
+ // Preview headers
+ this.compact_from.set_text(
+ yield format_originator_compact(cancellable)
+ );
+
+ // Full headers
+ Geary.EmailHeaderSet headers = this.headers;
+ yield fill_originator_addresses(
+ headers.from, headers.reply_to, headers.sender, cancellable
+ );
+ yield fill_header_addresses(
+ this.to_header, headers.to, cancellable
+ );
+ yield fill_header_addresses(
+ this.cc_header, headers.cc, cancellable
+ );
+ yield fill_header_addresses(
+ this.bcc_header, headers.bcc, cancellable
+ );
}
}
@@ -686,8 +697,8 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
bool contact_load_images = (
- this.primary_originator != null &&
- this.primary_originator.load_remote_resources
+ this.primary_contact != null &&
+ this.primary_contact.load_remote_resources
);
if (this.load_remote_resources || contact_load_images) {
this.web_view.allow_remote_image_loading();
@@ -780,14 +791,18 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
return menu;
}
- private string format_originator_compact(Geary.RFC822.MailboxAddresses? from,
- string empty_from_text) {
+ private async string format_originator_compact(GLib.Cancellable cancellable)
+ throws GLib.Error {
+ Geary.RFC822.MailboxAddresses? from = this.headers.from;
string text = "";
if (from != null && from.size > 0) {
int i = 0;
Gee.List<Geary.RFC822.MailboxAddress> list = from.get_all();
foreach (Geary.RFC822.MailboxAddress addr in list) {
- text += addr.to_short_display();
+ Application.Contact originator = yield this.contacts.load(
+ addr, cancellable
+ );
+ text += originator.display_name;
if (++i < list.size)
// Translators: This separates multiple 'from'
@@ -795,21 +810,22 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
text += _(", ");
}
} else {
- text = empty_from_text;
+ text = this.empty_from_label;
}
return text;
}
- private void fill_originator_addresses(Geary.RFC822.MailboxAddresses? from,
- Geary.RFC822.MailboxAddresses? reply_to,
- Geary.RFC822.MailboxAddress? sender,
- string empty_from_text) {
+ private async void fill_originator_addresses(Geary.RFC822.MailboxAddresses? from,
+ Geary.RFC822.MailboxAddresses? reply_to,
+ Geary.RFC822.MailboxAddress? sender,
+ GLib.Cancellable? cancellable)
+ throws GLib.Error {
// Show any From header addresses
if (from != null && from.size > 0) {
foreach (Geary.RFC822.MailboxAddress address in from) {
ContactFlowBoxChild child = new ContactFlowBoxChild(
- this.contacts.get(address),
+ yield this.contacts.load(address, cancellable),
address,
ContactFlowBoxChild.Type.FROM
);
@@ -818,7 +834,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
} else {
Gtk.Label label = new Gtk.Label(null);
- label.set_text(empty_from_text);
+ label.set_text(this.empty_from_label);
Gtk.FlowBoxChild child = new Gtk.FlowBoxChild();
child.add(label);
@@ -832,7 +848,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
if (sender != null &&
(from == null || !from.contains_normalized(sender.address))) {
ContactFlowBoxChild child = new ContactFlowBoxChild(
- this.contacts.get(sender),
+ yield this.contacts.load(sender, cancellable),
sender
);
this.searchable_addresses.add(child);
@@ -846,7 +862,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
foreach (Geary.RFC822.MailboxAddress address in reply_to) {
if (from == null || !from.contains_normalized(address.address)) {
ContactFlowBoxChild child = new ContactFlowBoxChild(
- this.contacts.get(address),
+ yield this.contacts.load(address, cancellable),
address
);
this.searchable_addresses.add(child);
@@ -857,14 +873,16 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
}
- private void fill_header_addresses(Gtk.Grid header,
- Geary.RFC822.MailboxAddresses? addresses) {
+ private async void fill_header_addresses(Gtk.Grid header,
+ Geary.RFC822.MailboxAddresses? addresses,
+ GLib.Cancellable? cancellable)
+ throws GLib.Error {
if (addresses != null && addresses.size > 0) {
Gtk.FlowBox box = header.get_children().nth(0).data as Gtk.FlowBox;
if (box != null) {
foreach (Geary.RFC822.MailboxAddress address in addresses) {
ContactFlowBoxChild child = new ContactFlowBoxChild(
- this.contacts.get(address),
+ yield this.contacts.load(address, cancellable),
address
);
this.searchable_addresses.add(child);
@@ -1159,8 +1177,8 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
case 2:
// Show images for sender
show_images(false);
- if (this.primary_originator != null) {
- this.primary_originator.set_remote_resource_loading.begin(
+ if (this.primary_contact != null) {
+ this.primary_contact.set_remote_resource_loading.begin(
true, null
);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]