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 Jul 21, 2023
1 parent deddb89 commit 899395e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
14 changes: 3 additions & 11 deletions lib/Service/Sync/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
namespace OCA\Mail\Service\Sync;

use OCA\Mail\Account;
use OCA\Mail\Contracts\IUserPreferences;
use OCA\Mail\Db\Mailbox;
use OCA\Mail\Db\MailboxMapper;
use OCA\Mail\Db\Message;
Expand Down Expand Up @@ -66,26 +65,20 @@ class SyncService {
/** @var MailboxSync */
private $mailboxSync;

/** @var IUserPreferences */
private $preferences;

public function __construct(ImapToDbSynchronizer $synchronizer,
FilterStringParser $filterStringParser,
MailboxMapper $mailboxMapper,
MessageMapper $messageMapper,
PreviewEnhancer $previewEnhancer,
LoggerInterface $logger,
MailboxSync $mailboxSync,
IUserPreferences $preferences) {
MailboxSync $mailboxSync) {
$this->synchronizer = $synchronizer;
$this->filterStringParser = $filterStringParser;
$this->mailboxMapper = $mailboxMapper;
$this->messageMapper = $messageMapper;
$this->previewEnhancer = $previewEnhancer;
$this->logger = $logger;
$this->mailboxSync = $mailboxSync;
$this->preferences = $preferences;

}

/**
Expand Down Expand Up @@ -163,19 +156,18 @@ private function getDatabaseSyncChanges(Account $account,
} else {
$newIds = $this->messageMapper->findNewIds($mailbox, $knownIds);
}
$order = $this->preferences->getPreference($this->currentUserId, 'sort-order', 'newest') === 'newest' ? 'DESC': 'ASC';

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, $order, null, $newUids);
$newIds = $this->messageMapper->findIdsByQuery($mailbox, $query, 'DESC', 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, $order, null, $changedUids);
$changedIds = $this->messageMapper->findIdsByQuery($mailbox, $query, 'DESC', null, $changedUids);
} else {
$changedIds = $knownIds;
}
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public function testIndex(): void {
['debug', false, true],
['version', '0.0.0', '26.0.0'],
['app.mail.attachment-size-limit', 0, 123],
['sort-order', 'newest', 'newest'],
]);
$this->config->expects($this->exactly(6))
->method('getAppValue')
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Service/Search/MailSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testFindMessagesNotCached() {
$this->search->findMessages(
$account,
$mailbox,
'newest',
'DESC',
null,
null,
null
Expand All @@ -110,7 +110,7 @@ public function testFindMessagesLocked() {
$this->search->findMessages(
$account,
$mailbox,
'newest',
'DESC',
null,
null,
null
Expand Down

0 comments on commit 899395e

Please sign in to comment.