[geary/wip/289-folder-not-fully-populated] Improve how the client triggers conversation auto-loading



commit 6e5c51cd0291c8a9072a421238e10b2d61b33e7f
Author: Michael Gratton <mike vee net>
Date:   Thu Apr 4 19:48:55 2019 +1100

    Improve how the client triggers conversation auto-loading
    
    Ensure in both ConversationListView and GearyController that before
    increasing the conversation window size, that the ConversationMonitor
    actualy has more email to load. When an load has finished, check that
    the list could acyually use some more, so if we get to the end of the
    scrollbar, before that happens, more will still be pciked up.
    
    This (hopefully) fixes the autoloading sometimes getting stuck and not
    loading more.

 src/client/application/geary-controller.vala       |  9 +++--
 .../conversation-list/conversation-list-view.vala  | 46 +++++++++-------------
 2 files changed, 25 insertions(+), 30 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 0a12e4d5..bf2b3a16 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -3025,11 +3025,14 @@ public class GearyController : Geary.BaseObject {
         }
     }
 
-    private void on_scan_completed() {
+    private void on_scan_completed(Geary.App.ConversationMonitor monitor) {
         // Done scanning.  Check if we have enough messages to fill
         // the conversation list; if not, trigger a load_more();
-        if (!main_window.conversation_list_has_scrollbar()) {
-            debug("Not enough messages, loading more for folder %s", current_folder.to_string());
+        if (!main_window.conversation_list_has_scrollbar() &&
+            monitor == this.current_conversations &&
+            monitor.can_load_more) {
+            debug("Not enough messages, loading more for folder %s",
+                  current_folder.to_string());
             on_load_more();
         }
     }
diff --git a/src/client/conversation-list/conversation-list-view.vala 
b/src/client/conversation-list/conversation-list-view.vala
index 8cc8160d..73b74755 100644
--- a/src/client/conversation-list/conversation-list-view.vala
+++ b/src/client/conversation-list/conversation-list-view.vala
@@ -12,9 +12,6 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
 
     private bool enable_load_more = true;
 
-    // Used to avoid repeated calls to load_more(). Contains the last "upper" bound of the
-    // scroll adjustment seen at the call to load_more().
-    private double last_upper = -1.0;
     private bool reset_adjustment = false;
     private Geary.App.ConversationMonitor? conversation_monitor;
     private Gee.Set<Geary.App.Conversation>? current_visible_conversations = null;
@@ -101,7 +98,6 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
             old_store.rows_reordered.disconnect(on_rows_changed);
             old_store.row_changed.disconnect(on_rows_changed);
             old_store.row_deleted.disconnect(on_rows_changed);
-            old_store.row_deleted.disconnect(on_row_deleted);
             old_store.destroy();
         }
 
@@ -110,7 +106,6 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
             new_store.rows_reordered.connect(on_rows_changed);
             new_store.row_changed.connect(on_rows_changed);
             new_store.row_deleted.connect(on_rows_changed);
-            new_store.row_deleted.connect(on_row_deleted);
             new_store.conversations_removed.connect(on_conversations_removed);
             new_store.conversations_added.connect(on_conversations_added);
         }
@@ -140,6 +135,20 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
         }
     }
 
+    private void check_load_more() {
+        // Check if we're at the very bottom of the list. If we are,
+        // it's time to issue a load_more signal.
+        Gtk.Adjustment adjustment = ((Gtk.Scrollable) this).get_vadjustment();
+        double upper = adjustment.get_upper();
+        double threshold = upper - adjustment.page_size - LOAD_MORE_HEIGHT;
+        if (this.conversation_monitor.can_load_more &&
+            adjustment.get_value() >= threshold) {
+            load_more();
+        }
+
+        schedule_visible_conversations_changed();
+    }
+
     private void on_conversation_monitor_changed() {
         if (conversation_monitor != null) {
             conversation_monitor.scan_started.disconnect(on_scan_started);
@@ -155,11 +164,12 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
     }
 
     private void on_scan_started() {
-        enable_load_more = false;
+        this.enable_load_more = false;
     }
 
     private void on_scan_completed() {
-        enable_load_more = true;
+        this.enable_load_more = true;
+        check_load_more();
 
         // Select the first conversation, if autoselect is enabled,
         // nothing has been selected yet and we're not composing.
@@ -323,20 +333,9 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
     }
 
     private void on_value_changed() {
-        if (!enable_load_more)
-            return;
-
-        // Check if we're at the very bottom of the list. If we are, it's time to
-        // issue a load_more signal.
-        Gtk.Adjustment adjustment = ((Gtk.Scrollable) this).get_vadjustment();
-        double upper = adjustment.get_upper();
-        if (adjustment.get_value() >= upper - adjustment.page_size - LOAD_MORE_HEIGHT &&
-            upper > last_upper) {
-            load_more();
-            last_upper = upper;
+        if (this.enable_load_more) {
+            check_load_more();
         }
-
-        schedule_visible_conversations_changed();
     }
 
     private static Gtk.TreeViewColumn create_column(ConversationListStore.Column column,
@@ -463,13 +462,6 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
         }
     }
 
-    private void on_row_deleted(Gtk.TreePath path) {
-        // if one or more rows are deleted in the model, reset the last upper limit so scrolling to
-        // the bottom will always activate a reload (this is particularly important if the model
-        // is cleared)
-        last_upper = -1.0;
-    }
-
     private void on_rows_changed() {
         schedule_visible_conversations_changed();
     }


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