[geary/mjog/phantom-parent-folders] Geary.ImapEngine.GenericAccount: Fix duplicate folders on first load



commit df2bce4eb87f442e847ad283e145179a366d9e61
Author: Michael Gratton <mike vee net>
Date:   Thu Apr 23 11:13:06 2020 +1000

    Geary.ImapEngine.GenericAccount: Fix duplicate folders on first load
    
    When loading an account for the first time, folders may not be processed
    such that parents are handled first, leading to phantom folders created
    for them.
    
    This is particularly noticeable for GMail accounts, where the `[GMail]`
    folder would typically show up, since it was created twice.

 .../imap-engine/imap-engine-generic-account.vala      | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 1bce766e..6a83ff01 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -1079,11 +1079,20 @@ internal class Geary.ImapEngine.UpdateRemoteFolders : AccountOperation {
     }
 
     public override async void execute(Cancellable cancellable) throws Error {
-        Gee.Map<FolderPath, Geary.Folder> existing_folders =
-            Geary.traverse<Geary.Folder>(this.account.list_folders())
-            .to_hash_map<FolderPath>(f => f.path);
-        Gee.Map<FolderPath, Imap.Folder> remote_folders =
-            new Gee.HashMap<FolderPath, Imap.Folder>();
+        // Use sorted maps here to a) aid debugging, and b) ensure
+        // that parent folders are processed before child folders
+        var existing_folders = new Gee.TreeMap<FolderPath,Folder>(
+            (a,b) => a.compare_to(b)
+        );
+        var remote_folders = new Gee.TreeMap<FolderPath,Imap.Folder>(
+            (a,b) => a.compare_to(b)
+        );
+
+        Geary.traverse<Geary.Folder>(
+            this.account.list_folders()
+        ).add_all_to_map<FolderPath>(
+            existing_folders, f => f.path
+        );
 
         GenericAccount account = (GenericAccount) this.account;
         Imap.AccountSession remote = yield account.claim_account_session(


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