diff --git a/lib/Db/Message.php b/lib/Db/Message.php index 47181897b5..ea27288b0a 100644 --- a/lib/Db/Message.php +++ b/lib/Db/Message.php @@ -261,6 +261,15 @@ public function setFlag(string $flag, bool $value = true) { } public function jsonSerialize() { + $tags = $this->getTags(); + $indexed = array_combine( + array_map( + function (Tag $tag) { + return $tag->getImapLabel(); + }, $tags), + $tags + ); + return [ 'databaseId' => $this->getId(), 'uid' => $this->getUid(), @@ -277,7 +286,7 @@ public function jsonSerialize() { 'junk' => $this->getFlagJunk(), 'mdnsent' => $this->getFlagMdnsent(), ], - 'tags' => $this->getTags(), + 'tags' => $indexed, 'from' => $this->getFrom()->jsonSerialize(), 'to' => $this->getTo()->jsonSerialize(), 'cc' => $this->getCc()->jsonSerialize(), diff --git a/lib/Db/Tag.php b/lib/Db/Tag.php index b28149871e..261f9c393a 100644 --- a/lib/Db/Tag.php +++ b/lib/Db/Tag.php @@ -57,12 +57,12 @@ public function __construct() { */ public function jsonSerialize() { return [ - 'databaseId' => $this->getId(), + 'id' => $this->getId(), 'userId' => $this->getUserId(), 'displayName' => $this->getDisplayName(), 'imapLabel' => $this->getImapLabel(), 'color' => $this->getColor(), - 'isDefaultTag' => $this->getisDefaultTag(), + 'isDefaultTag' => $this->getIsDefaultTag(), ]; } } diff --git a/lib/Db/TagMapper.php b/lib/Db/TagMapper.php index 9a775223e4..2195902239 100644 --- a/lib/Db/TagMapper.php +++ b/lib/Db/TagMapper.php @@ -32,31 +32,22 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IL10N; -use Psr\Log\LoggerInterface; /** * @template-extends QBMapper */ class TagMapper extends QBMapper { - /** @var LoggerInterface */ - private $logger; - /** @var IL10N */ private $l10n; public function __construct(IDBConnection $db, - LoggerInterface $logger, IL10N $l10n) { parent::__construct($db, 'mail_tags'); - $this->logger = $logger; $this->l10n = $l10n; } /** - * @param string $imapLabel - * @return Entity - * * @throws DoesNotExistException */ public function getTagByImapLabel(string $imapLabel, string $userId): Entity { @@ -71,10 +62,6 @@ public function getTagByImapLabel(string $imapLabel, string $userId): Entity { } /** - * @param integer $id - * @param string $userId - * @return Entity - * * @throws DoesNotExistException */ public function getTagForUser(int $id, string $userId): Entity { @@ -89,10 +76,7 @@ public function getTagForUser(int $id, string $userId): Entity { } /** - * @param integer $id - * @param string $userId - * @return array - * + * @return Tag[] * @throws DoesNotExistException */ public function getAllTagForUser(string $userId): array { @@ -105,12 +89,7 @@ public function getAllTagForUser(string $userId): array { return $this->findEntities($qb); } - /** - * @param integer $id - * @param string $userId - * @return Entity - * * @throws DoesNotExistException */ public function getTag(int $id): Entity { @@ -124,14 +103,9 @@ public function getTag(int $id): Entity { /** * Tag a message in the DB * - * To tag (flag) a message on IMAP, @see OCA\Mail\Service\MailManager::tagMessage - * - * @param Tag $tag - * @param string $messageId - * @param string $userId - * @return void + * To tag (flag) a message on IMAP, @see \OCA\Mail\Service\MailManager::tagMessage */ - public function tagMessage(Tag $tag, string $messageId, string $userId) { + public function tagMessage(Tag $tag, string $messageId, string $userId): void { /** @var Tag $exists */ try { $exists = $this->getTagByImapLabel($tag->getImapLabel(), $userId); @@ -150,11 +124,9 @@ public function tagMessage(Tag $tag, string $messageId, string $userId) { /** * Remove a tag from a DB message * - * @param Tag $tag - * @param string $messageId - * @return void + * This does not(!) untag a message on IMAP */ - public function untagMessage(Tag $tag, string $messageId) { + public function untagMessage(Tag $tag, string $messageId): void { $qb = $this->db->getQueryBuilder(); $qb->delete('mail_message_tags') ->where($qb->expr()->eq('imap_message_id', $qb->createNamedParameter($messageId))) @@ -163,22 +135,22 @@ public function untagMessage(Tag $tag, string $messageId) { } /** - * @param array $messages - * @return array + * @param Message[] $messages + * @return Tag[][] */ - public function getAllTagsForMessages(array $messages):array { + public function getAllTagsForMessages(array $messages): array { $ids = array_map(function (Message $message) { return $message->getMessageId(); }, $messages); $qb = $this->db->getQueryBuilder(); - $ids = $qb->select('mt.*') + $idsQuery = $qb->select('mt.*') ->from('mail_message_tags', 'mt') ->where( $qb->expr()->in('imap_message_id', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_STR_ARRAY)) ); - $qb = $qb->execute(); - $queryResult = $qb->fetchAll(); + $idsQuery = $idsQuery->execute(); + $queryResult = $idsQuery->fetchAll(); if (empty($queryResult)) { return []; } @@ -199,12 +171,9 @@ public function getAllTagsForMessages(array $messages):array { * The array_udiff can be removed and the insert warpped in * an exception as soon as NC20 is not supported any more * - * @param MailAccount $account - * @return void - * * @link https://github.com/nextcloud/mail/issues/25 */ - public function createDefaultTags(MailAccount $account) { + public function createDefaultTags(MailAccount $account): void { $tags = []; for ($i = 1; $i < 6; $i++) { $tag = new Tag(); diff --git a/lib/Migration/Version1100Date20210304143008.php b/lib/Migration/Version1100Date20210304143008.php index 261a6cf700..06c6f65782 100644 --- a/lib/Migration/Version1100Date20210304143008.php +++ b/lib/Migration/Version1100Date20210304143008.php @@ -112,7 +112,6 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt * @param array $options */ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { - // repair step! $accounts = $this->mailAccountMapper->getAllUserIdsWithAccounts(); foreach ($accounts as $account) { $this->tagMapper->createDefaultTags($account); diff --git a/lib/Model/IMAPMessage.php b/lib/Model/IMAPMessage.php index 3318cb3af0..24743ef44b 100644 --- a/lib/Model/IMAPMessage.php +++ b/lib/Model/IMAPMessage.php @@ -752,8 +752,8 @@ public function toDbMessage(int $mailboxId, MailAccount $account): Message { * * @link https://github.com/nextcloud/mail/issues/25 * - * @param array $tags - * @return array + * @param string[] $tags + * @return Tag[] */ private function generateTagEntites(array $tags, string $userId): array { $t = [];