Skip to content

Commit

Permalink
fixup! add sorting capabilities to mail
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <[email protected]>
  • Loading branch information
hamza221 committed Oct 16, 2023
1 parent 6eddd06 commit b0c6a4f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/Sync/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit b0c6a4f

Please sign in to comment.