From 0265786ab056ed3745e34d5cbc34a58758e0b8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bellegarde?= Date: Fri, 25 Aug 2023 22:22:53 +0200 Subject: [PATCH] engine: Do not stop unread calculation if no id provided Fix #929 --- src/engine/imap-db/imap-db-folder.vala | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/engine/imap-db/imap-db-folder.vala b/src/engine/imap-db/imap-db-folder.vala index 8c14fa0f..3f9d6f85 100644 --- a/src/engine/imap-db/imap-db-folder.vala +++ b/src/engine/imap-db/imap-db-folder.vala @@ -1068,7 +1068,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { yield db.exec_transaction_async(Db.TransactionType.RW, (cx, cancellable) => { // fetch flags for each email Gee.Map? map = do_get_email_flags(cx, - to_mark, cancellable); + to_mark, ListFlags.NONE, cancellable); if (map == null) return Db.TransactionOutcome.COMMIT; @@ -1138,7 +1138,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { Gee.Collection ids, Cancellable? cancellable) throws Error { Gee.Map? map = null; yield db.exec_transaction_async(Db.TransactionType.RO, (cx, cancellable) => { - map = do_get_email_flags(cx, ids, cancellable); + map = do_get_email_flags(cx, ids, ListFlags.NONE, cancellable); return Db.TransactionOutcome.SUCCESS; }, cancellable); @@ -1155,7 +1155,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { yield db.exec_transaction_async(Db.TransactionType.RW, (cx, cancellable) => { // TODO get current flags, compare to ones being set Gee.Map? existing_map = - do_get_email_flags(cx, map.keys, cancellable); + do_get_email_flags(cx, map.keys, ListFlags.NONE, cancellable); if (existing_map != null) { foreach(ImapDB.EmailIdentifier id in map.keys) { @@ -1241,10 +1241,10 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { Gee.Set removed_ids = new Gee.HashSet(); yield db.exec_transaction_async(Db.TransactionType.RW, (cx) => { Gee.List locs; - if (ids != null) - locs = do_get_locations_for_ids(cx, ids, ListFlags.INCLUDE_MARKED_FOR_REMOVE, cancellable); - else + if (ids == null || ids.size == 0) locs = do_get_all_locations(cx, ListFlags.INCLUDE_MARKED_FOR_REMOVE, cancellable); + else + locs = do_get_locations_for_ids(cx, ids, ListFlags.INCLUDE_MARKED_FOR_REMOVE, cancellable); if (locs == null || locs.size == 0) return Db.TransactionOutcome.DONE; @@ -1910,9 +1910,15 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { } private Gee.Map? do_get_email_flags(Db.Connection cx, - Gee.Collection ids, Cancellable? cancellable) throws Error { - Gee.List? locs = do_get_locations_for_ids(cx, ids, ListFlags.NONE, - cancellable); + Gee.Collection? ids, ListFlags flags, + Cancellable? cancellable) throws Error { + Gee.List? locs; + + if (ids == null || ids.size == 0) + locs = do_get_all_locations(cx, flags, cancellable); + else + locs = do_get_locations_for_ids(cx, ids, flags, cancellable); + if (locs == null || locs.size == 0) return null; @@ -2553,14 +2559,12 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { private int do_get_unread_count_for_ids(Db.Connection cx, Gee.Collection? ids, Cancellable? cancellable) throws Error { - if (ids == null || ids.size == 0) - return 0; // Fetch flags for each email and update this folder's unread count. // (Note that this only flags for emails which have NOT been marked for removal // are included.) Gee.Map? flag_map = do_get_email_flags(cx, - ids, cancellable); + ids, ListFlags.INCLUDE_MARKED_FOR_REMOVE, cancellable); if (flag_map != null) return Geary.traverse(flag_map.values).count_matching(f => f.is_unread());