[geary/wip/713150-conversations] Fixes bug when finding lowest email id in folder of known ids



commit d7b8d783823c09f1a3c332ed6d0219976a8291e8
Author: Jim Nelson <jim yorba org>
Date:   Wed Feb 25 18:07:56 2015 -0800

    Fixes bug when finding lowest email id in folder of known ids
    
    This is a separate bug unto itself; new code merely triggered it.
    Might be worth moving into master as a separate fix.

 src/engine/app/app-conversation-monitor.vala       |    4 +--
 .../imap-engine/imap-engine-minimal-folder.vala    |   39 +++++++++++++-------
 2 files changed, 27 insertions(+), 16 deletions(-)
---
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index 5b939dc..b98fa84 100644
--- a/src/engine/app/app-conversation-monitor.vala
+++ b/src/engine/app/app-conversation-monitor.vala
@@ -451,7 +451,6 @@ public class Geary.App.ConversationMonitor : BaseObject {
             folder.to_string(), email_ids.size);
         
         // don't re-process existing emails
-        /*
         Gee.Collection<EmailIdentifier> trimmed_ids = traverse<EmailIdentifier>(email_ids)
             .filter(id => !all_email_id_to_conversation.has_key(id))
             .to_hash_set();
@@ -460,8 +459,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
         
         email_ids = trimmed_ids;
         if (email_ids.size == 0)
-            return false;
-        */
+            return;
         
         Gee.Collection<AssociatedEmails>? associations = null;
         try {
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index 440578f..c8e460e 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -1026,23 +1026,36 @@ private class Geary.ImapEngine.MinimalFolder : Geary.Folder, Geary.FolderSupport
         low = null;
         high = null;
         
+        // Get paths for all email identifiers
         Gee.MultiMap<Geary.EmailIdentifier, Geary.FolderPath>? map
             = yield account.get_containing_folders_async(ids, cancellable);
+        if (map == null || map.size == 0)
+            return;
         
-        if (map != null) {
-            Gee.ArrayList<Geary.EmailIdentifier> in_folder = new Gee.ArrayList<Geary.EmailIdentifier>();
-            foreach (Geary.EmailIdentifier id in map.get_keys()) {
-                if (path in map.get(id))
-                    in_folder.add(id);
-            }
-            
-            if (in_folder.size > 0) {
-                Gee.SortedSet<Geary.EmailIdentifier> sorted = Geary.EmailIdentifier.sort(in_folder);
-                
-                low = sorted.first();
-                high = sorted.last();
-            }
+        // only deal with email identifiers in this folder
+        Gee.ArrayList<Geary.EmailIdentifier> in_folder = new Gee.ArrayList<Geary.EmailIdentifier>();
+        foreach (Geary.EmailIdentifier id in map.get_keys()) {
+            if (path in map.get(id))
+                in_folder.add(id);
         }
+        
+        if (in_folder.size == 0)
+            return;
+        
+        // get new Emails for these; they will have their UIDs and can be sorted properly
+        Gee.List<Email>? list = yield local_folder.list_email_by_sparse_id_async(in_folder,
+            Email.Field.NONE, ImapDB.Folder.ListFlags.NONE, cancellable);
+        if (list == null || list.size == 0)
+            return;
+        
+        Gee.HashSet<EmailIdentifier> db_ids = traverse<Email>(list)
+            .map<EmailIdentifier>(email => email.id)
+            .to_hash_set();
+        
+        Gee.SortedSet<Geary.EmailIdentifier> sorted = Geary.EmailIdentifier.sort(db_ids);
+        
+        low = sorted.first();
+        high = sorted.last();
     }
     
     private void on_email_complete(Gee.Collection<Geary.EmailIdentifier> email_ids) {


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