Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/Db
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2022-03-25 13:37:57 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2022-04-07 19:34:32 +0300
commit9063c6e36e314c77401fa4be5abf02a41c0d0a57 (patch)
tree336be567876f3a792a2b6f091fddc820c89203bf /lib/Db
parent2bbcbb9d59e30c87126f048d41c7030680c773d3 (diff)
Add a background worker job that flushes the outbox
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Db')
-rw-r--r--lib/Db/LocalAttachmentMapper.php3
-rw-r--r--lib/Db/LocalMessageMapper.php33
-rw-r--r--lib/Db/RecipientMapper.php4
3 files changed, 39 insertions, 1 deletions
diff --git a/lib/Db/LocalAttachmentMapper.php b/lib/Db/LocalAttachmentMapper.php
index 3bb38a2f4..50bb25158 100644
--- a/lib/Db/LocalAttachmentMapper.php
+++ b/lib/Db/LocalAttachmentMapper.php
@@ -60,6 +60,9 @@ class LocalAttachmentMapper extends QBMapper {
* @return LocalAttachment[]
*/
public function findByLocalMessageIds(array $localMessageIds): array {
+ if (empty($localMessageIds)) {
+ return [];
+ }
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
diff --git a/lib/Db/LocalMessageMapper.php b/lib/Db/LocalMessageMapper.php
index 3b36381b6..71029e672 100644
--- a/lib/Db/LocalMessageMapper.php
+++ b/lib/Db/LocalMessageMapper.php
@@ -28,6 +28,7 @@ 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;
@@ -117,6 +118,38 @@ class LocalMessageMapper extends QBMapper {
}
/**
+ * Find all messages that should be sent
+ *
+ * @param int $time upper bound send time stamp
+ *
+ * @return LocalMessage[]
+ */
+ public function findDue(int $time): array {
+ $qb = $this->db->getQueryBuilder();
+ $select = $qb->select('*')
+ ->from($this->getTableName())
+ ->where(
+ $qb->expr()->isNotNull('send_at'),
+ $qb->expr()->lte('send_at', $qb->createNamedParameter($time, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)
+ );
+ $messages = $this->findEntities($select);
+ $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;
+ }, $messages);
+ }
+
+ /**
* @param Recipient[] $to
* @param Recipient[] $cc
* @param Recipient[] $bcc
diff --git a/lib/Db/RecipientMapper.php b/lib/Db/RecipientMapper.php
index 8de6728ff..4f5b8bcc0 100644
--- a/lib/Db/RecipientMapper.php
+++ b/lib/Db/RecipientMapper.php
@@ -57,8 +57,10 @@ class RecipientMapper extends QBMapper {
* @return Recipient[]
*/
public function findByLocalMessageIds(array $localMessageIds): array {
+ if (empty($localMessageIds)) {
+ return [];
+ }
$qb = $this->db->getQueryBuilder();
-
$query = $qb->select('*')
->from($this->getTableName())
->where(