diff --git a/lib/Contracts/IMailSearch.php b/lib/Contracts/IMailSearch.php index a579808950..849f9ddd44 100644 --- a/lib/Contracts/IMailSearch.php +++ b/lib/Contracts/IMailSearch.php @@ -36,6 +36,7 @@ public function findMessage(Account $account, * @param string|null $filter * @param int|null $cursor * @param int|null $limit + * @param string|null $userId * * @return Message[] * @@ -47,7 +48,8 @@ public function findMessages(Account $account, string $sortOrder, ?string $filter, ?int $cursor, - ?int $limit): array; + ?int $limit, + ?string $userId): array; /** * @param IUser $user diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index 88b6299e21..29b0029eca 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -152,7 +152,8 @@ public function index(int $mailboxId, $order, $filter === '' ? null : $filter, $cursor, - $limit + $limit, + $this->currentUserId ) ); } diff --git a/lib/IMAP/PreviewEnhancer.php b/lib/IMAP/PreviewEnhancer.php index d87f861c18..28cbb03843 100644 --- a/lib/IMAP/PreviewEnhancer.php +++ b/lib/IMAP/PreviewEnhancer.php @@ -38,21 +38,16 @@ class PreviewEnhancer { /** @var AvatarService */ private $avatarService; - /** @var string|null */ - private $userId; - public function __construct(IMAPClientFactory $clientFactory, ImapMapper $imapMapper, DbMapper $dbMapper, LoggerInterface $logger, - AvatarService $avatarService, - string $userId) { + AvatarService $avatarService) { $this->clientFactory = $clientFactory; $this->imapMapper = $imapMapper; $this->mapper = $dbMapper; $this->logger = $logger; $this->avatarService = $avatarService; - $this->userId = $userId; } /** @@ -60,7 +55,7 @@ public function __construct(IMAPClientFactory $clientFactory, * * @return Message[] */ - public function process(Account $account, Mailbox $mailbox, array $messages, string $mode = 'sync'): array { + public function process(Account $account, Mailbox $mailbox, array $messages, bool $preLoadAvatars = false, ?string $userId): array { $needAnalyze = array_reduce($messages, static function (array $carry, Message $message) { if ($message->getStructureAnalyzed()) { // Nothing to do @@ -70,12 +65,11 @@ public function process(Account $account, Mailbox $mailbox, array $messages, str return array_merge($carry, [$message->getUid()]); }, []); - // If we are in the API call, we need to fetch the avatar for the sender - if ($mode === 'apiCall') { + if ($preLoadAvatars) { foreach ($messages as $message) { - $from = $message->getFrom()->first() ; - if ($message->getAvatar() === null && $from !== null && $from->getEmail() !== null && $this->userId !== null) { - $avatar = $this->avatarService->getAvatar($from->getEmail(), $this->userId); + $from = $message->getFrom()->first(); + if ($message->getAvatar() === null && $from !== null && $from->getEmail() !== null && $userId !== null) { + $avatar = $this->avatarService->getAvatar($from->getEmail(), $userId, true); $message->setAvatar($avatar); } } diff --git a/lib/Service/AvatarService.php b/lib/Service/AvatarService.php index 351c44fca8..b2369eab82 100644 --- a/lib/Service/AvatarService.php +++ b/lib/Service/AvatarService.php @@ -91,12 +91,12 @@ private function hasAllowedMime(Avatar $avatar): bool { * @param string $uid * @return Avatar|null */ - public function getAvatar(string $email, string $uid): ?Avatar { + public function getAvatar(string $email, string $uid, bool $cachedOnly = false): ?Avatar { $cachedAvatar = $this->cache->get($email, $uid); if ($cachedAvatar) { return $cachedAvatar; } - if ($cachedAvatar === false) { + if ($cachedAvatar === false || $cachedOnly) { // We know there is no avatar return null; } diff --git a/lib/Service/Search/MailSearch.php b/lib/Service/Search/MailSearch.php index 3efb8e32b5..54eaac0f8e 100644 --- a/lib/Service/Search/MailSearch.php +++ b/lib/Service/Search/MailSearch.php @@ -91,7 +91,8 @@ public function findMessages(Account $account, string $sortOrder, ?string $filter, ?int $cursor, - ?int $limit): array { + ?int $limit, + ?string $userId): array { if ($mailbox->hasLocks($this->timeFactory->getTime())) { throw MailboxLockedException::from($mailbox); } @@ -119,7 +120,8 @@ public function findMessages(Account $account, $this->getIdsLocally($account, $mailbox, $query, $sortOrder, $limit), $sortOrder, ), - 'apiCall' + true, + $userId ); } diff --git a/src/components/Avatar.vue b/src/components/Avatar.vue index 543f0772b4..1e358504be 100644 --- a/src/components/Avatar.vue +++ b/src/components/Avatar.vue @@ -18,6 +18,7 @@