[geary/wip/improve-claiming-folder-session: 1/9] Add Geary.Account.is_online property



commit 8d1b5b565c6fe3c84aaececa5ce2d575af999003
Author: Michael Gratton <mike vee net>
Date:   Sat Nov 10 09:25:05 2018 +1100

    Add Geary.Account.is_online property
    
    This will be useful for displaying this status to the user in the
    future, and allows removing MinimalFolder.is_remote_available, which is
    hopelessly innacturate in the face of network problems.

 src/engine/api/geary-account.vala                        | 14 +++++++++++++-
 src/engine/imap-engine/imap-engine-generic-account.vala  |  3 +++
 src/engine/imap-engine/imap-engine-minimal-folder.vala   | 16 ----------------
 .../replay-ops/imap-engine-abstract-list-email.vala      |  2 +-
 test/engine/api/geary-account-mock.vala                  |  2 ++
 5 files changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/src/engine/api/geary-account.vala b/src/engine/api/geary-account.vala
index 32ed7e8b..6e11ae6e 100644
--- a/src/engine/api/geary-account.vala
+++ b/src/engine/api/geary-account.vala
@@ -28,7 +28,19 @@ public abstract class Geary.Account : BaseObject {
 
 
     public Geary.AccountInformation information { get; protected set; }
-    
+
+    /**
+     * Determines if this account appears to be online.
+     *
+     * This property is true if the account is to the best of the
+     * engine's knowledge is online, i.e. it is enabled, has been able
+     * to connect to the remote incoming mail server, and so on. Some
+     * network problems are not immediately obvious however, and so at
+     * times the value of this property may be inaccurate. At best it
+     * should be treated as a heuristic.
+     */
+    public abstract bool is_online { get; protected set; }
+
     public Geary.ProgressMonitor search_upgrade_monitor { get; protected set; }
     public Geary.ProgressMonitor db_upgrade_monitor { get; protected set; }
     public Geary.ProgressMonitor db_vacuum_monitor { get; protected set; }
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 26dbcf32..273fcf3e 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -25,6 +25,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         Geary.SpecialFolderType.ARCHIVE,
     };
 
+    public override bool is_online { get; protected set; default = false; }
+
     /** This account's IMAP session pool. */
     public Imap.ClientSessionManager session_pool { get; private set; }
 
@@ -975,6 +977,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     }
 
     private void on_pool_session_ready(bool is_ready) {
+        this.is_online = is_ready;
         if (is_ready) {
             // Now have a valid session, so credentials must be good
             this.authentication_failures = 0;
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index 80f55dad..6b0c0ba0 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -64,22 +64,6 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
     /** The IMAP database representation of the folder. */
     internal ImapDB.Folder local_folder { get; private set; }
 
-    /**
-     * Determines if a remote session is currently available.
-     *
-     * If this property is //true//, then a subsequent call to {@link
-     * wait_for_remote_async} or {@link claim_remote_session} should
-     * return immediately without error.
-     */
-    internal bool is_remote_available {
-        get {
-            return (
-                this.remote_wait_semaphore.can_pass &&
-                this.remote_wait_semaphore.result
-            );
-        }
-    }
-
     internal ReplayQueue? replay_queue { get; private set; default = null; }
     internal EmailPrefetcher email_prefetcher { get; private set; }
 
diff --git a/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala 
b/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala
index 271c4416..11974947 100644
--- a/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala
+++ b/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala
@@ -215,7 +215,7 @@ private abstract class Geary.ImapEngine.AbstractListEmail : Geary.ImapEngine.Sen
      */
     protected async Trillian is_fully_expanded_async() throws Error {
         Trillian is_fully_expanded = Trillian.UNKNOWN;
-        if (this.owner.is_remote_available) {
+        if (this.owner.account.is_online) {
             Imap.FolderSession remote =
                 yield this.owner.claim_remote_session(this.cancellable);
             int remote_count = remote.folder.properties.email_total;
diff --git a/test/engine/api/geary-account-mock.vala b/test/engine/api/geary-account-mock.vala
index ebc25528..78831ab7 100644
--- a/test/engine/api/geary-account-mock.vala
+++ b/test/engine/api/geary-account-mock.vala
@@ -31,6 +31,8 @@ public class Geary.MockAccount : Account, MockObject {
     }
 
 
+    public override bool is_online { get; protected set; default = false; }
+
     protected Gee.Queue<ExpectedCall> expected {
         get; set; default = new Gee.LinkedList<ExpectedCall>();
     }


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