diff options
author | Anna Larch <anna@nextcloud.com> | 2022-04-13 00:00:10 +0300 |
---|---|---|
committer | julia.kirschenheuter <julia.kirschenheuter@nextcloud.com> | 2022-04-13 16:04:39 +0300 |
commit | e7b057e630727113d5f51d651840b9ea25586a4a (patch) | |
tree | 99b6f801ef8364a7736fdb4d5b57d3f8b50a7beb /lib/Db | |
parent | ea93911bd2eff92a205a827c7c595a683053b3ce (diff) |
Fix message attachments not sending
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib/Db')
-rw-r--r-- | lib/Db/LocalMessageMapper.php | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/Db/LocalMessageMapper.php b/lib/Db/LocalMessageMapper.php index 71029e672..d99550ace 100644 --- a/lib/Db/LocalMessageMapper.php +++ b/lib/Db/LocalMessageMapper.php @@ -28,7 +28,6 @@ namespace OCA\Mail\Db; use OCP\AppFramework\Db\DoesNotExistException; use OCP\DB\Exception as DBException; use Throwable; -use function array_filter; use function array_map; use OCP\AppFramework\Db\QBMapper; use OCP\DB\QueryBuilder\IQueryBuilder; @@ -133,19 +132,31 @@ class LocalMessageMapper extends QBMapper { $qb->expr()->lte('send_at', $qb->createNamedParameter($time, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT) ); $messages = $this->findEntities($select); + + if (empty($messages)) { + return []; + } + $ids = array_map(function (LocalMessage $message) { return $message->getId(); }, $messages); + $attachments = $this->attachmentMapper->findByLocalMessageIds($ids); $recipients = $this->recipientMapper->findByLocalMessageIds($ids); - return array_map(static function ($message) use ($attachments, $recipients) { - $message->setAttachments(array_filter($attachments, function (LocalAttachment $attachment) use ($message) { - return $attachment->getLocalMessageId() === $message->getId(); - })); - $message->setRecipients(array_filter($recipients, function (Recipient $recipient) use ($message) { - return $recipient->getLocalMessageId() === $message->getId(); - })); - return $message; + + $recipientMap = []; + foreach ($recipients as $r) { + $recipientMap[$r->getLocalMessageId()][] = $r; + } + $attachmentMap = []; + foreach ($attachments as $a) { + $attachmentMap[$a->getLocalMessageId()][] = $a; + } + + return array_map(static function ($localMessage) use ($attachmentMap, $recipientMap) { + $localMessage->setAttachments($attachmentMap[$localMessage->getId()] ?? []); + $localMessage->setRecipients($recipientMap[$localMessage->getId()] ?? []); + return $localMessage; }, $messages); } |