[geary: 8/13] Some more changes requested by Michael



commit f172a13fb184fed6bc44d84b778d867f685b7f53
Author: James Magahern <james magahern com>
Date:   Wed Oct 17 23:34:11 2018 -0700

    Some more changes requested by Michael
    
    1. Coalesce inserted ids into one InsertOperation
    2. Adds a new parameter to `get_emails` to allow developer to specify whether or not they want deleted 
emails filtered out
    3. Reverts remove_conversation back to old behavior, but specifies false for filter_deleted (from 2)

 src/engine/app/app-conversation-monitor.vala        | 12 ++++++++----
 src/engine/app/app-conversation.vala                | 21 +++++++++++++++++----
 .../conversation-monitor/app-conversation-set.vala  | 21 +++++++++------------
 3 files changed, 34 insertions(+), 20 deletions(-)
---
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index edc0f43e..21529388 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<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>();
         foreach (EmailIdentifier id in map.keys) {
@@ -857,10 +858,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
             if (conversation == null) {
                 if (folder == this.base_folder) {
                     debug("Unflagging email %s for deletion resurrects conversation", id.to_string());
-
-                    Gee.HashSet<EmailIdentifier> inserted_emails = new Gee.HashSet<EmailIdentifier>();
-                    inserted_emails.add(id);
-                    this.queue.add(new InsertOperation(this, inserted_emails));
+                    inserted_ids.add(id);
                 }
 
                 continue;
@@ -885,7 +883,13 @@ public class Geary.App.ConversationMonitor : BaseObject {
             } 
         }
 
+        // Notify about inserted messages
+        this.queue.add(new InsertOperation(this, inserted_ids));
+
         // Notify self about removed conversations
+        // NOTE: We are only notifying the conversation monitor about the removed conversations instead of
+        // enqueuing a RemoveOperation, because these messages haven't actually been removed. They're only
+        // hidden at the conversation-level for being marked as deleted.
         removed(
             removed_conversations,
             new Gee.HashMultiMap<Conversation, Email>(),
diff --git a/src/engine/app/app-conversation.vala b/src/engine/app/app-conversation.vala
index 1a89e9ac..c929f436 100644
--- a/src/engine/app/app-conversation.vala
+++ b/src/engine/app/app-conversation.vala
@@ -180,6 +180,16 @@ public class Geary.App.Conversation : BaseObject {
         return get_single_email(Ordering.RECV_DATE_DESCENDING, location);
     }
 
+    public Gee.Collection<Email>
+        get_emails_flagged_for_deletion(Location location,
+                                        Gee.Collection<FolderPath>? blacklist = null) {
+        Gee.Collection<Email> emails = get_emails(Ordering.NONE, location, blacklist, false);
+        Iterable<Email> filtered = traverse<Email>(emails);
+        return filtered.filter(
+            (e) => e.email_flags.is_deleted()
+        ).to_array_list();
+    }
+
     /**
      * Returns all the email in the conversation sorted and filtered according to the specifiers.
      *
@@ -191,7 +201,8 @@ public class Geary.App.Conversation : BaseObject {
     public Gee.Collection<Email>
         get_emails(Ordering ordering,
                    Location location = Location.ANYWHERE,
-                   Gee.Collection<FolderPath>? blacklist = null) {
+                   Gee.Collection<FolderPath>? blacklist = null,
+                   bool filter_deleted = true) {
         Gee.Collection<Email> email;
         switch (ordering) {
             case Ordering.SENT_DATE_ASCENDING:
@@ -234,9 +245,11 @@ public class Geary.App.Conversation : BaseObject {
         }
 
         // Filter emails waiting to be expunged (\DELETED)
-        filtered = filtered.filter(
-            (e) => (e.email_flags != null) ? !e.email_flags.is_deleted() : true
-        );
+        if (filter_deleted) {
+            filtered = filtered.filter(
+                (e) => (e.email_flags != null) ? !e.email_flags.is_deleted() : true
+            );
+        }
 
         if (blacklist != null && !blacklist.is_empty) {
             if (blacklist.size == 1) {
diff --git a/src/engine/app/conversation-monitor/app-conversation-set.vala 
b/src/engine/app/conversation-monitor/app-conversation-set.vala
index 451139aa..0d749bcc 100644
--- a/src/engine/app/conversation-monitor/app-conversation-set.vala
+++ b/src/engine/app/conversation-monitor/app-conversation-set.vala
@@ -191,18 +191,15 @@ private class Geary.App.ConversationSet : BaseObject {
      * Removes a conversation from the set.
      */
     public void remove_conversation(Conversation conversation) {
-        Gee.HashSet<Geary.EmailIdentifier> ids_to_remove = new Gee.HashSet<Geary.EmailIdentifier>();
-        foreach (Gee.Map.Entry<EmailIdentifier, Conversation> entry in email_id_map.entries) {
-            if (entry.value == conversation) {
-                ids_to_remove.add(entry.key);
-            }
-        }
-
-        foreach (EmailIdentifier id in ids_to_remove) {
-            Geary.Email? email = conversation.get_email_by_id(id);
-            if (email != null)
-                remove_email_from_conversation(conversation, email);
-        }
+        Gee.Collection<Email> conversation_emails = conversation.get_emails(
+            Conversation.Ordering.NONE,     // ordering
+            Conversation.Location.ANYWHERE, // location
+            null,                           // blacklist
+            false                           // filter deleted (false, so we remove emails that are flagged 
for deletion too)
+        );
+
+        foreach (Geary.Email conversation_email in conversation_emails)
+            remove_email_from_conversation(conversation, conversation_email);
 
         if (!_conversations.remove(conversation))
             error("Conversation %s already removed from set", conversation.to_string());


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