From b4749cce393c7b2ce508a68d4a8ecae66d21341e Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Tue, 25 Sep 2018 23:59:28 +1000 Subject: [PATCH] Simplify the process of creating new local folders somewhat Enable local folders to be created with one call, rather than two. --- src/engine/imap-db/imap-db-account.vala | 12 ++++++--- .../imap-engine-generic-account.vala | 26 +++++++------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala index d0f6f277..28de8efc 100644 --- a/src/engine/imap-db/imap-db-account.vala +++ b/src/engine/imap-db/imap-db-account.vala @@ -384,9 +384,10 @@ private class Geary.ImapDB.Account : BaseObject { private void on_outbox_email_sent(Geary.RFC822.Message rfc822) { email_sent(rfc822); } - - public async void clone_folder_async(Geary.Imap.Folder imap_folder, Cancellable? cancellable = null) - throws Error { + + public async Folder clone_folder_async(Geary.Imap.Folder imap_folder, + GLib.Cancellable? cancellable = null) + throws GLib.Error { check_open(); Geary.Imap.FolderProperties properties = imap_folder.properties; @@ -426,8 +427,11 @@ private class Geary.ImapDB.Account : BaseObject { return Db.TransactionOutcome.COMMIT; }, cancellable); + + // XXX can't we create this from the INSERT above? + return yield fetch_folder_async(path, cancellable); } - + public async void delete_folder_async(Geary.Folder folder, Cancellable? cancellable) throws Error { check_open(); diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala b/src/engine/imap-engine/imap-engine-generic-account.vala index f90f3e05..6e7ec146 100644 --- a/src/engine/imap-engine/imap-engine-generic-account.vala +++ b/src/engine/imap-engine/imap-engine-generic-account.vala @@ -1240,27 +1240,19 @@ internal class Geary.ImapEngine.UpdateRemoteFolders : AccountOperation { .map(e => (Geary.Folder) e.value) .to_array_list(); - // For folders to add, clone them and their properties locally + // For folders to add, clone them and their properties + // locally, then add to the account ImapDB.Account local = ((GenericAccount) this.account).local; - foreach (Geary.Imap.Folder remote_folder in to_add) { - try { - yield local.clone_folder_async(remote_folder, cancellable); - } catch (Error err) { - debug("Unable to add/remove folder %s to local store: %s", remote_folder.path.to_string(), - err.message); - } - } - - // Create Geary.Folder objects for all added folders Gee.ArrayList to_build = new Gee.ArrayList(); foreach (Geary.Imap.Folder remote_folder in to_add) { try { - to_build.add(yield local.fetch_folder_async(remote_folder.path, cancellable)); - } catch (Error convert_err) { - // This isn't fatal, but irksome ... in the future, when local folders are - // removed, it's possible for one to disappear between cloning it and fetching - // it - debug("Unable to fetch local folder after cloning: %s", convert_err.message); + to_build.add( + yield local.clone_folder_async(remote_folder, cancellable) + ); + } catch (Error err) { + debug("Unable to clone folder %s in local store: %s", + remote_folder.path.to_string(), + err.message); } } this.generic_account.add_folders(to_build, false);