[geary/mjog/invert-folder-class-hierarchy] client: Update required email flags and preview loading



commit d9f061ec578e490d83fef8220a602a524a36a1d6
Author: Michael Gratton <mike vee net>
Date:   Sun Mar 7 20:53:04 2021 +1100

    client: Update required email flags and preview loading
    
    Add an explicit load step when displaying a conversation in the
    conversation viewer for loading email with previews, so that the preview
    requirement can be removed from the fields passed to the conversation
    monitor, and hence email will be displayed even when not yet downloaded.
    
    Update ConversationMessage previews when messages are fully loaded so
    their previews will be available if first loaded without them.

 src/client/application/application-client.vala     |  3 ++
 .../application/application-main-window.vala       | 10 +++---
 .../conversation-list/conversation-list-store.vala |  5 +--
 .../conversation-viewer/conversation-email.vala    |  1 -
 .../conversation-viewer/conversation-list-box.vala | 37 ++++++++++++++++------
 .../conversation-viewer/conversation-message.vala  | 31 +++++++++++-------
 6 files changed, 54 insertions(+), 33 deletions(-)
---
diff --git a/src/client/application/application-client.vala b/src/client/application/application-client.vala
index bcc705fe9..222eac7b7 100644
--- a/src/client/application/application-client.vala
+++ b/src/client/application/application-client.vala
@@ -385,6 +385,9 @@ public class Application.Client : Gtk.Application {
         this.engine.minimum_email_fields = (
             Geary.App.ConversationMonitor.REQUIRED_FIELDS |
             Geary.App.SearchFolder.REQUIRED_FIELDS |
+            // Only include conversation list req's here, not the
+            // conversation viewer's, since that will ensure it's own
+            // prereqs.
             ConversationListStore.REQUIRED_FIELDS
         );
 
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index 164c21076..077c720d1 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -779,12 +779,10 @@ public class Application.MainWindow :
 
                 this.conversations = new Geary.App.ConversationMonitor(
                     to_select,
-                    // Include fields for the conversation viewer as well so
-                    // conversations can be displayed without having to go
-                    // back to the db
-                    ConversationListStore.REQUIRED_FIELDS |
-                    ConversationListBox.REQUIRED_FIELDS |
-                    ConversationEmail.REQUIRED_FOR_CONSTRUCT,
+                    // Only include conversation list req's here, not
+                    // the conversation viewer's, since that will
+                    // ensure it's own prereqs.
+                    ConversationListStore.REQUIRED_FIELDS,
                     MIN_CONVERSATION_COUNT
                 );
                 this.progress_monitor.add(this.conversations.progress_monitor);
diff --git a/src/client/conversation-list/conversation-list-store.vala 
b/src/client/conversation-list/conversation-list-store.vala
index 7f6ab2718..09de4a365 100644
--- a/src/client/conversation-list/conversation-list-store.vala
+++ b/src/client/conversation-list/conversation-list-store.vala
@@ -21,11 +21,8 @@ public class ConversationListStore : Gtk.ListStore {
         Geary.Email.Field.PROPERTIES
     );
 
-    // XXX Remove REQUIRED_FOR_BODY when PREVIEW has been fixed. See Bug 714317.
     public const Geary.Email.Field WITH_PREVIEW_FIELDS = (
-        REQUIRED_FIELDS |
-        Geary.Email.Field.PREVIEW |
-        Geary.Email.REQUIRED_FOR_MESSAGE
+        REQUIRED_FIELDS | PREVIEW
     );
 
     public enum Column {
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index 89d4e61b5..89dba71c4 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -28,7 +28,6 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
     /** Fields that must be available for constructing the view. */
     internal const Geary.Email.Field REQUIRED_FOR_CONSTRUCT = (
         Geary.Email.Field.ENVELOPE |
-        Geary.Email.Field.PREVIEW |
         Geary.Email.Field.FLAGS
     );
 
diff --git a/src/client/conversation-viewer/conversation-list-box.vala 
b/src/client/conversation-viewer/conversation-list-box.vala
index 802e209f6..9967c5ebc 100644
--- a/src/client/conversation-viewer/conversation-list-box.vala
+++ b/src/client/conversation-viewer/conversation-list-box.vala
@@ -20,7 +20,7 @@
  */
 public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
 
-    /** Fields that must be available for listing conversation email. */
+    /** Fields that must be available for displaying conversations. */
     public const Geary.Email.Field REQUIRED_FIELDS = (
         // Sorting the conversation
         Geary.Email.Field.DATE |
@@ -764,10 +764,25 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
         throws GLib.Error {
         set_sort_func(null);
 
-        Gee.Collection<Geary.Email>? all_email = this.conversation.get_emails(
+        Gee.Collection<Geary.Email>? convo_email = this.conversation.get_emails(
             Geary.App.Conversation.Ordering.SENT_DATE_ASCENDING
         );
 
+        // Load all email up-font including the preview, but include
+        // partials so if the preview does not exist this does not
+        // throw an error.
+        Gee.Collection<Geary.Email> full_email_set =
+            yield this.email_store.get_multiple_email_by_id(
+                this.conversation.get_email_ids(),
+                REQUIRED_FIELDS |
+                ConversationEmail.REQUIRED_FOR_CONSTRUCT |
+                Geary.Email.Field.PREVIEW,
+                INCLUDING_PARTIAL,
+                this.cancellable
+            );
+        Gee.Map<Geary.EmailIdentifier,Geary.Email> full_email_map =
+            Geary.Email.emails_to_map(full_email_set);
+
         // Work out what the first interesting email is, and load it
         // before all of the email before and after that so we can
         // load them in an optimal order.
@@ -785,34 +800,36 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
             var first_scroll = Geary.Collection.first(valid_scroll_to);
 
             if (first_scroll != null) {
-                foreach (Geary.Email email in all_email) {
+                foreach (Geary.Email email in convo_email) {
+                    var full_email = full_email_map.get(email.id);
                     if (first_interesting == null) {
                         if (email.id == first_scroll) {
-                            first_interesting = email;
+                            first_interesting = full_email;
                         } else {
                             // Inserted reversed so most recent uninteresting
                             // rows are added first.
-                            uninteresting.insert(0, email);
+                            uninteresting.insert(0, full_email);
                         }
                     } else {
-                        post_interesting.add(email);
+                        post_interesting.add(full_email);
                     }
                 }
             }
         }
 
         if (first_interesting == null) {
-            foreach (Geary.Email email in all_email) {
+            foreach (Geary.Email email in convo_email) {
+                var full_email = full_email_map.get(email.id);
                 if (first_interesting == null) {
                     if (is_interesting(email)) {
-                        first_interesting = email;
+                        first_interesting = full_email;
                     } else {
                         // Inserted reversed so most recent uninteresting
                         // rows are added first.
-                        uninteresting.insert(0, email);
+                        uninteresting.insert(0, full_email);
                     }
                 } else {
-                    post_interesting.add(email);
+                    post_interesting.add(full_email);
                 }
             }
         }
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index b987dbdd6..a3680f978 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -534,18 +534,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
 
         this.compact_from.get_style_context().add_class(FROM_CLASS);
 
-        if (preview != null) {
-            string clean_preview = preview;
-            if (preview.length > MAX_PREVIEW_BYTES) {
-                clean_preview = Geary.String.safe_byte_substring(
-                    preview, MAX_PREVIEW_BYTES
-                );
-                // Add an ellipsis in case the view is wider is wider than
-                // the text
-                clean_preview += "…";
-            }
-            this.compact_body.set_text(clean_preview);
-        }
+        update_preview(preview ?? "");
 
         // Full headers. These are partially done here and partially
         // in load_contacts.
@@ -882,6 +871,11 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
             throw new GLib.IOError.CANCELLED("Conversation load cancelled");
         }
 
+        var preview = message.get_preview();
+        if (preview != "") {
+            update_preview(preview);
+        }
+
         if (this.web_view == null) {
             initialize_web_view();
         }
@@ -978,6 +972,19 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
         this.date.set_tooltip_text(date_tooltip);
     }
 
+    private void update_preview(string preview) {
+        string clean_preview = preview;
+        if (preview.length > MAX_PREVIEW_BYTES) {
+            clean_preview = Geary.String.safe_byte_substring(
+                preview, MAX_PREVIEW_BYTES
+            );
+            // Add an ellipsis in case the view is wider is wider than
+            // the text
+            clean_preview += "…";
+        }
+        this.compact_body.set_text(clean_preview);
+    }
+
     private SimpleAction add_action(string name, bool enabled, VariantType? type = null) {
         SimpleAction action = new SimpleAction(name, type);
         action.set_enabled(enabled);


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