[geary: 5/13] Moves flag change handling from list-store to conversation-monitor.



commit 3e1efb4f8b3e8e149d5b8d8a0b2339de8ea00d44
Author: James Magahern <james magahern com>
Date:   Wed Oct 10 02:01:56 2018 -0700

    Moves flag change handling from list-store to conversation-monitor.
    
    Also adds a unit test for such behavior.

 .../conversation-list/conversation-list-store.vala |  6 ------
 src/engine/app/app-conversation-monitor.vala       | 14 ++++++++++++++
 test/engine/app/app-conversation-monitor-test.vala | 22 ++++++++++++++++++++++
 3 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/client/conversation-list/conversation-list-store.vala 
b/src/client/conversation-list/conversation-list-store.vala
index 125c0526..7b82381a 100644
--- a/src/client/conversation-list/conversation-list-store.vala
+++ b/src/client/conversation-list/conversation-list-store.vala
@@ -463,12 +463,6 @@ public class ConversationListStore : Gtk.ListStore {
     
     private void on_email_flags_changed(Geary.App.Conversation conversation) {
         refresh_flags(conversation);
-
-        // Remove conversation if get_emails yields an empty collection -- this probably means
-        // the conversation was deleted. 
-        if (conversation.get_emails(Geary.App.Conversation.Ordering.NONE).size == 0) {
-            remove_conversation(conversation);
-        }
         
         // refresh previews because the oldest unread message is displayed as the preview, and if
         // that's changed, need to change the preview
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index 642884f4..93147e91 100644
--- a/src/engine/app/app-conversation-monitor.vala
+++ b/src/engine/app/app-conversation-monitor.vala
@@ -850,6 +850,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
 
     private void on_account_email_flags_changed(Geary.Folder folder,
                                                 Gee.Map<EmailIdentifier,EmailFlags> map) {
+        Gee.HashSet<Conversation> removed_conversations = new Gee.HashSet<Conversation>();
         foreach (EmailIdentifier id in map.keys) {
             Conversation? conversation = this.conversations.get_by_email_identifier(id);
             if (conversation == null)
@@ -861,7 +862,20 @@ public class Geary.App.ConversationMonitor : BaseObject {
 
             email.set_flags(map.get(id));
             notify_email_flags_changed(conversation, email);
+
+            // Remove conversation if get_emails yields an empty collection -- this probably means
+            // the conversation was deleted.
+            if (conversation.get_emails(Geary.App.Conversation.Ordering.NONE).size == 0) {
+                Logging.debug(Logging.Flag.CONVERSATIONS, 
+                    "Flagging email %s for deletion evaporates conversation %s", 
+                    id.to_string(), conversation.to_string());
+                
+                this.conversations.remove_conversation(conversation);
+                removed_conversations.add(conversation);
+            }
         }
+
+        notify_conversations_removed(removed_conversations);
     }
 
     private void on_operation_error(ConversationOperation op, Error err) {
diff --git a/test/engine/app/app-conversation-monitor-test.vala 
b/test/engine/app/app-conversation-monitor-test.vala
index 285a62b4..a00fe04e 100644
--- a/test/engine/app/app-conversation-monitor-test.vala
+++ b/test/engine/app/app-conversation-monitor-test.vala
@@ -25,6 +25,7 @@ class Geary.App.ConversationMonitorTest : TestCase {
         add_test("base_folder_message_appended", base_folder_message_appended);
         add_test("base_folder_message_removed", base_folder_message_removed);
         add_test("external_folder_message_appended", external_folder_message_appended);
+        add_test("conversation_marked_as_deleted", conversation_marked_as_deleted);
     }
 
     public override void set_up() {
@@ -332,6 +333,27 @@ class Geary.App.ConversationMonitorTest : TestCase {
                      "Appended email not present in conversation");
     }
 
+    public void conversation_marked_as_deleted() throws Error {
+        Email e1 = setup_email(1);
+
+        Gee.MultiMap<EmailIdentifier,FolderPath> paths =
+            new Gee.HashMultiMap<EmailIdentifier,FolderPath>();
+        paths.set(e1.id, this.base_folder.path);
+
+        ConversationMonitor monitor = setup_monitor({e1}, paths);
+        assert_int(1, monitor.size, "Conversation count");
+
+        // Mark message as deleted
+        Gee.HashMap<EmailIdentifier,EmailFlags> flags_changed =
+            new Gee.HashMap<EmailIdentifier,EmailFlags>();
+        flags_changed.set(e1.id, new EmailFlags.with(EmailFlags.DELETED));
+        this.account.email_flags_changed(this.base_folder, flags_changed);
+
+        wait_for_signal(monitor, "email-flags-changed"); 
+
+        assert_int(0, monitor.size, "Conversation count should now be zero after being marked deleted.");
+    }
+
     private Email setup_email(int id, Email? references = null) {
         Email email = new Email(new MockEmailIdentifer(id));
         DateTime now = new DateTime.now_local();


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