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 7d98c9a commit deddb89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/Service/Search/MailSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public function findMessagesGlobally(IUser $user,
}

return $this->messageMapper->findByIds($user->getUID(),
$this->getIdsGlobally($user, $query, $limit)
$this->getIdsGlobally($user, $query, $limit),
'newest'
);
}

Expand Down
14 changes: 11 additions & 3 deletions lib/Service/Sync/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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 @@ -65,20 +66,26 @@ 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) {
MailboxSync $mailboxSync,
IUserPreferences $preferences) {
$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 @@ -156,18 +163,19 @@ 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, 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, null, $changedUids);
$changedIds = $this->messageMapper->findIdsByQuery($mailbox, $query, $order, null, $changedUids);
} else {
$changedIds = $knownIds;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Service/Search/MailSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2020 Christoph Wurst <[email protected]>
*
* @author 2020 Christoph Wurst <[email protected]>
*/MailSearchTest.php:99
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
Expand Down

0 comments on commit deddb89

Please sign in to comment.