From b0c6a4fe2518dc1da1fa9736581f1fccb2f163c5 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Mon, 16 Oct 2023 16:43:51 +0200 Subject: [PATCH] fixup! add sorting capabilities to mail Signed-off-by: hamza221 --- lib/Db/MessageMapper.php | 4 ++-- lib/Service/Sync/SyncService.php | 8 ++++---- src/store/actions.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Db/MessageMapper.php b/lib/Db/MessageMapper.php index 1f510fb273..0d2f6ff40b 100644 --- a/lib/Db/MessageMapper.php +++ b/lib/Db/MessageMapper.php @@ -1272,9 +1272,9 @@ public function findNewIds(Mailbox $mailbox, array $ids, ?int $lastMessageTimest } // TODO: flip comparison with sort order? - if ($lastMessageTimestamp !== null) { + if ($lastMessageTimestamp !== null && $sortOrder === IMailSearch::ORDER_OLDEST_FIRST) { // Don't consider old "new messages" as new when their UID has already been seen before - $wheres[] = $select->expr()->gt('m.sent_at', $select->createNamedParameter($lastMessageTimestamp, IQueryBuilder::PARAM_INT)); + $wheres[] = $select->expr()->lt('m.sent_at', $select->createNamedParameter($lastMessageTimestamp, IQueryBuilder::PARAM_INT)); } $select diff --git a/lib/Service/Sync/SyncService.php b/lib/Service/Sync/SyncService.php index 46bafc0d02..a666aa0559 100644 --- a/lib/Service/Sync/SyncService.php +++ b/lib/Service/Sync/SyncService.php @@ -163,18 +163,18 @@ private function getDatabaseSyncChanges(Account $account, } else { $newIds = $this->messageMapper->findNewIds($mailbox, $knownIds, $lastMessageTimestamp, $sortOrder); } - + $order = $sortOrder === 'oldest' ? IMailSearch::ORDER_OLDEST_FIRST : IMailSearch::ORDER_NEWEST_FIRST; if ($query !== null) { // Filter new messages to those that also match the current filter $newUids = $this->messageMapper->findUidsForIds($mailbox, $newIds); - $newIds = $this->messageMapper->findIdsByQuery($mailbox, $query, $sortOrder, null, $newUids); + $newIds = $this->messageMapper->findIdsByQuery($mailbox, $query, $order, null, $newUids); } $new = $this->messageMapper->findByMailboxAndIds($mailbox, $account->getUserId(), $newIds); // TODO: $changed = $this->messageMapper->findChanged($account, $mailbox, $uids); if ($query !== null) { $changedUids = $this->messageMapper->findUidsForIds($mailbox, $knownIds); - $changedIds = $this->messageMapper->findIdsByQuery($mailbox, $query, $sortOrder, null, $changedUids); + $changedIds = $this->messageMapper->findIdsByQuery($mailbox, $query, $order, null, $changedUids); } else { $changedIds = $knownIds; } @@ -189,7 +189,7 @@ private function getDatabaseSyncChanges(Account $account, $this->previewEnhancer->process($account, $mailbox, $new), $changed, $vanished, - $this->messageMapper->findLastMessageTimestamp($account, $mailbox, $query, $sortOrder), + $this->messageMapper->findLastMessageTimestamp($account, $mailbox, $query, $order), $mailbox->getStats() ); } diff --git a/src/store/actions.js b/src/store/actions.js index 323ab57126..6728bcbbf4 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -783,7 +783,7 @@ export default { } const ids = getters.getEnvelopes(mailboxId, query).map((env) => env.databaseId) - const lastTimestamp = getters.getLastMessageTimestamp(mailboxId, query) + const lastTimestamp = getters.getPreference('sort-order') ==='newest' ? getters.getLastMessageTimestamp(mailboxId, query) : getters.getEnvelopes(mailboxId, query)[0].dateInt logger.debug(`mailbox sync of ${mailboxId} (${query}) has ${ids.length} known IDs. ${lastTimestamp} is the last known message timestamp`, { mailbox }) return syncEnvelopes(mailbox.accountId, mailboxId, ids, lastTimestamp, query, init, getters.getPreference('sort-order')) .then((syncData) => {