[geary/mjog/invert-folder-class-hierarchy: 356/362] Geary.App.ConversationMonitor: Simplify implementation a bit




commit d2da085c1a7ebec085195387730643c1032c1d94
Author: Michael Gratton <mike vee net>
Date:   Sat Feb 20 08:09:38 2021 +1100

    Geary.App.ConversationMonitor: Simplify implementation a bit
    
    Just connect to account signals and handle in and out of folder
    emission there, not connecting to the account and the base folder.
    
    Now private stop monitoring method is called once, just move its
    body into the public method.

 src/engine/app/app-conversation-monitor.vala       | 96 +++++++++-------------
 test/engine/app/app-conversation-monitor-test.vala |  6 --
 2 files changed, 38 insertions(+), 64 deletions(-)
---
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index 5fdd0bf5d..15bdd0e1b 100644
--- a/src/engine/app/app-conversation-monitor.vala
+++ b/src/engine/app/app-conversation-monitor.vala
@@ -313,13 +313,11 @@ public class Geary.App.ConversationMonitor : BaseObject, Logging.Source {
         this.is_monitoring = true;
         this.base_was_opened = false;
 
-        this.base_folder.email_appended.connect(on_folder_email_appended);
-        this.base_folder.email_inserted.connect(on_folder_email_inserted);
-        this.base_folder.email_removed.connect(on_folder_email_removed);
-        this.base_folder.account.email_appended_to_folder.connect(on_account_email_appended);
-        this.base_folder.account.email_inserted_into_folder.connect(on_account_email_inserted);
-        this.base_folder.account.email_removed_from_folder.connect(on_account_email_removed);
-        this.base_folder.account.email_flags_changed_in_folder.connect(on_account_email_flags_changed);
+        var account = this.base_folder.account;
+        account.email_appended_to_folder.connect(on_email_appended);
+        account.email_inserted_into_folder.connect(on_email_inserted);
+        account.email_removed_from_folder.connect(on_email_removed);
+        account.email_flags_changed_in_folder.connect(on_email_flags_changed);
 
         this.queue.operation_error.connect(on_operation_error);
         this.queue.add(new FillWindowOperation(this));
@@ -364,7 +362,23 @@ public class Geary.App.ConversationMonitor : BaseObject, Logging.Source {
         if (this.is_monitoring) {
             // Set now to prevent reentrancy during yield or signal
             this.is_monitoring = false;
-            yield stop_monitoring_internal(cancellable);
+
+            var account = this.base_folder.account;
+            account.email_appended_to_folder.disconnect(on_email_appended);
+            account.email_inserted_into_folder.disconnect(on_email_inserted);
+            account.email_removed_from_folder.disconnect(on_email_removed);
+            account.email_flags_changed_in_folder.disconnect(on_email_flags_changed);
+
+            yield this.queue.stop_processing_async(cancellable);
+
+            // Cancel outstanding ops so they don't block the queue closing
+            this.operation_cancellable.cancel();
+
+            if (this.base_was_opened) {
+                ((Geary.RemoteFolder) this.base_folder).stop_monitoring();
+                this.base_was_opened = false;
+            }
+
             is_closing = true;
         }
         return is_closing;
@@ -617,27 +631,6 @@ public class Geary.App.ConversationMonitor : BaseObject, Logging.Source {
         email_flags_changed(conversation, email);
     }
 
-    private async void stop_monitoring_internal(GLib.Cancellable? cancellable)
-        throws GLib.Error {
-        this.base_folder.email_appended.disconnect(on_folder_email_appended);
-        this.base_folder.email_inserted.disconnect(on_folder_email_inserted);
-        this.base_folder.email_removed.disconnect(on_folder_email_removed);
-        this.base_folder.account.email_appended_to_folder.disconnect(on_account_email_appended);
-        this.base_folder.account.email_inserted_into_folder.disconnect(on_account_email_inserted);
-        this.base_folder.account.email_removed_from_folder.disconnect(on_account_email_removed);
-        this.base_folder.account.email_flags_changed_in_folder.disconnect(on_account_email_flags_changed);
-
-        // Cancel outstanding ops so they don't block the queue closing
-        this.operation_cancellable.cancel();
-
-        if (this.base_was_opened) {
-            ((Geary.RemoteFolder) this.base_folder).stop_monitoring();
-            this.base_was_opened = false;
-        }
-
-        yield this.queue.stop_processing_async(cancellable);
-    }
-
     private async void process_email_async(Gee.Collection<Geary.Email>? emails,
                                            ProcessJobContext job)
         throws Error {
@@ -755,44 +748,31 @@ public class Geary.App.ConversationMonitor : BaseObject, Logging.Source {
               needed_message_ids.size, needed_messages.size);
     }
 
-    private void on_folder_email_appended(Gee.Collection<EmailIdentifier> appended) {
-        this.queue.add(new AppendOperation(this, appended));
-    }
-
-    private void on_folder_email_inserted(Gee.Collection<EmailIdentifier> inserted) {
-        this.queue.add(new InsertOperation(this, inserted));
-    }
-
-    private void on_folder_email_removed(Gee.Collection<EmailIdentifier> removed) {
-        this.queue.add(new RemoveOperation(this, this.base_folder, removed));
-    }
-
-    private void on_account_email_appended(Gee.Collection<EmailIdentifier> added,
-                                           Folder folder) {
-        if (folder != this.base_folder) {
-            this.queue.add(new ExternalAppendOperation(this, folder, added));
+    private void on_email_appended(Gee.Collection<EmailIdentifier> appended,
+                                   Folder folder) {
+        if (folder == this.base_folder) {
+            this.queue.add(new AppendOperation(this, appended));
+        } else {
+            this.queue.add(new ExternalAppendOperation(this, folder, appended));
         }
     }
 
-    private void on_account_email_inserted(Gee.Collection<EmailIdentifier> inserted,
-                                           Folder folder) {
-        // ExternalAppendOperation will check to determine if the
-        // email is relevant for some existing conversation before
-        // adding it, which is what we want here.
-        if (folder != this.base_folder) {
+    private void on_email_inserted(Gee.Collection<EmailIdentifier> inserted,
+                                   Folder folder) {
+        if (folder == this.base_folder) {
+            this.queue.add(new InsertOperation(this, inserted));
+        } else {
             this.queue.add(new ExternalAppendOperation(this, folder, inserted));
         }
     }
 
-    private void on_account_email_removed(Gee.Collection<EmailIdentifier> removed,
-                                          Folder folder) {
-        if (folder != this.base_folder) {
-            this.queue.add(new RemoveOperation(this, folder, removed));
-        }
+    private void on_email_removed(Gee.Collection<EmailIdentifier> removed,
+                                  Folder folder) {
+        this.queue.add(new RemoveOperation(this, this.base_folder, removed));
     }
 
-    private void on_account_email_flags_changed(Gee.Map<EmailIdentifier,EmailFlags> map,
-                                                Geary.Folder folder) {
+    private void on_email_flags_changed(Gee.Map<EmailIdentifier,EmailFlags> map,
+                                        Geary.Folder folder) {
         Gee.HashSet<EmailIdentifier> inserted_ids = new Gee.HashSet<EmailIdentifier>();
         Gee.HashSet<EmailIdentifier> removed_ids = new Gee.HashSet<EmailIdentifier>();
         Gee.HashSet<Conversation> removed_conversations = new Gee.HashSet<Conversation>();
diff --git a/test/engine/app/app-conversation-monitor-test.vala 
b/test/engine/app/app-conversation-monitor-test.vala
index d4ab4bd2f..b75f88ba1 100644
--- a/test/engine/app/app-conversation-monitor-test.vala
+++ b/test/engine/app/app-conversation-monitor-test.vala
@@ -406,12 +406,6 @@ class Geary.App.ConversationMonitorTest : TestCase {
         this.account.expect_call("get_containing_folders_async")
             .returns_object(paths);
 
-        // Should not be added, since it's actually in the base folder
-        this.account.email_appended_to_folder(
-            new Gee.ArrayList<EmailIdentifier>.wrap({e2.id}),
-            this.base_folder
-        );
-
         // Should be added, since it's an external message
         this.account.email_appended_to_folder(
             new Gee.ArrayList<EmailIdentifier>.wrap({e3.id}),


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