[geary/wip/135-contact-popovers: 7/26] Stop passing the avatar store all the way down to conversation message



commit 5ce9aa3013994d666a8b15162aa6cf1a8df9171b
Author: Michael Gratton <mike vee net>
Date:   Thu Mar 14 19:19:34 2019 +1100

    Stop passing the avatar store all the way down to conversation message
    
    Since avatars are loaded after messages are added to the viewer, we can
    just get it from the controller via the top-level window's app instance.
    This removes a substantial bit of needless complexity.

 src/client/application/geary-controller.vala       |  1 -
 .../conversation-viewer/conversation-email.vala    | 16 ++++-------
 .../conversation-viewer/conversation-list-box.vala | 14 +++-------
 .../conversation-viewer/conversation-message.vala  | 31 +++++++++-------------
 .../conversation-viewer/conversation-viewer.vala   |  6 ++---
 5 files changed, 23 insertions(+), 45 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index fca5162a..d2594d79 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1327,7 +1327,6 @@ public class GearyController : Geary.BaseObject {
                     viewer.load_conversation.begin(
                         convo,
                         store,
-                        this.avatars,
                         (obj, ret) => {
                             try {
                                 viewer.load_conversation.end(ret);
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index 58d1a980..96f818de 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -311,9 +311,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
     // Store from which to lookup contacts
     private Geary.ContactStore contact_store;
 
-    // Store from which to load avatars
-    private Application.AvatarStore avatar_store;
-
     // Cancellable to use when loading message content
     private GLib.Cancellable load_cancellable;
 
@@ -438,7 +435,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
      */
     public ConversationEmail(Geary.Email email,
                              Geary.App.EmailStore email_store,
-                             Application.AvatarStore avatar_store,
                              Configuration config,
                              bool is_sent,
                              bool is_draft,
@@ -449,7 +445,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         this.primary_originator = Util.Email.get_primary_originator(email);
         this.email_store = email_store;
         this.contact_store = email_store.account.get_contact_store();
-        this.avatar_store = avatar_store;
         this.config = config;
         this.load_cancellable = load_cancellable;
         this.message_bodies_loaded_lock =
@@ -577,14 +572,15 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
     /**
      * Loads the avatar for the primary message.
      */
-    public async void load_avatar(Application.AvatarStore store)
+    public async void load_avatar()
         throws GLib.Error {
         try {
-            yield this.primary_message.load_avatar(store, this.load_cancellable);
+            yield this.primary_message.load_avatar(this.load_cancellable);
         } catch (IOError.CANCELLED err) {
             // okay
         } catch (Error err) {
-            Geary.RFC822.MailboxAddress? from = this.primary_originator;
+            Geary.RFC822.MailboxAddress? from =
+                this.primary_message.primary_originator;
             debug("Avatar load failed for \"%s\": %s",
                   from != null ? from.to_string() : "<unknown>", err.message);
         }
@@ -863,9 +859,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.avatar_store, this.load_cancellable
-            );
+            attached_message.load_avatar.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 9799d97e..53d70d2d 100644
--- a/src/client/conversation-viewer/conversation-list-box.vala
+++ b/src/client/conversation-viewer/conversation-list-box.vala
@@ -471,9 +471,6 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
     // Used to load messages in conversation.
     private Geary.App.EmailStore email_store;
 
-    // Avatars for this conversation
-    private Application.AvatarStore avatar_store;
-
     // App config
     private Configuration config;
 
@@ -552,13 +549,11 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
      */
     public ConversationListBox(Geary.App.Conversation conversation,
                                Geary.App.EmailStore email_store,
-                               Application.AvatarStore avatar_store,
                                Configuration config,
                                Gtk.Adjustment adjustment) {
         base_ref();
         this.conversation = conversation;
         this.email_store = email_store;
-        this.avatar_store = avatar_store;
         this.config = config;
 
         this.search = new SearchManager(this, conversation);
@@ -640,7 +635,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(this.avatar_store);
+        interesting_row.view.load_avatar.begin();
         yield interesting_row.expand();
         this.finish_loading.begin(
             query, uninteresting, post_interesting
@@ -811,7 +806,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(this.avatar_store);
+            yield row.view.load_avatar();
             if (is_interesting(email)) {
                 yield row.expand();
             }
@@ -846,7 +841,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(this.avatar_store);
+            yield row.view.load_avatar();
             if (i_mail_loaded % 10 == 0)
                 yield throttle_loading();
             ++i_mail_loaded;
@@ -898,7 +893,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
 
         if (!this.cancellable.is_cancelled()) {
             EmailRow row = add_email(full_email);
-            yield row.view.load_avatar(this.avatar_store);
+            yield row.view.load_avatar();
             this.search.highlight_row_if_matching(row);
             yield row.expand();
         }
@@ -920,7 +915,6 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
         ConversationEmail view = new ConversationEmail(
             email,
             this.email_store,
-            this.avatar_store,
             this.config,
             is_sent,
             is_draft(email),
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index cdb492c2..5a0c530c 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -46,7 +46,6 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
     private const string ACTION_SAVE_IMAGE = "save-image";
     private const string ACTION_SELECT_ALL = "select-all";
 
-
     // Widget used to display sender/recipient email addresses in
     // message header Gtk.FlowBox instances.
     private class AddressFlowBoxChild : Gtk.FlowBoxChild {
@@ -154,6 +153,10 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
 
     private static GLib.VariantType MAILBOX_TYPE = new GLib.VariantType("(ss)");
 
+    /** Originator used for contact lookup, avatar, and so on. */
+    internal Geary.RFC822.MailboxAddress? primary_originator {
+        get; private set;
+    }
 
     /** Box containing the preview and full header widgets.  */
     [GtkChild]
@@ -168,8 +171,6 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
 
     private Configuration config;
 
-    private Geary.RFC822.MailboxAddress? primary_originator;
-
     private GLib.DateTime? local_date = null;
 
     [GtkChild]
@@ -618,25 +619,17 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
     /**
      * Starts loading the avatar for the message's sender.
      */
-    public async void load_avatar(Application.AvatarStore loader,
-                                  GLib.Cancellable load_cancelled)
+    public async void load_avatar(GLib.Cancellable cancellable)
         throws GLib.Error {
-        if (load_cancelled.is_cancelled()) {
-            throw new GLib.IOError.CANCELLED("Conversation load cancelled");
-        }
-
-        // We occasionally get crashes calling as below
-        // Gtk.Image.get_pixel_size() when the image is null. There's
-        // perhaps some race going on there. So we need to hard-code
-        // the size here and keep it in sync with
-        // ui/conversation-message.ui. :(
-        const int PIXEL_SIZE = 48;
-        if (this.primary_originator != null) {
+        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 = this.avatar.get_pixel_size() * window_scale;
-            int pixel_size = PIXEL_SIZE * window_scale;
+            int pixel_size = Application.AvatarStore.PIXEL_SIZE * window_scale;
             Gdk.Pixbuf? avatar_buf = yield loader.load(
-                this.primary_originator, pixel_size, load_cancelled
+                this.primary_originator, pixel_size, cancellable
             );
             if (avatar_buf != null) {
                 this.avatar.set_from_surface(
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index 46f1a294..fa989206 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -1,6 +1,6 @@
 /*
  * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2016 Michael Gratton <mike vee net>
+ * Copyright 2016,2019 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later). See the COPYING file in this distribution.
@@ -230,15 +230,13 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface {
      * Shows a conversation in the viewer.
      */
     public async void load_conversation(Geary.App.Conversation conversation,
-                                        Geary.App.EmailStore email_store,
-                                        Application.AvatarStore avatar_store)
+                                        Geary.App.EmailStore email_store)
         throws GLib.Error {
         remove_current_list();
 
         ConversationListBox new_list = new ConversationListBox(
             conversation,
             email_store,
-            avatar_store,
             this.config,
             this.conversation_scroller.get_vadjustment()
         );


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