Skip to content

Commit

Permalink
fixup! Fix: perform bulk message actions
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Dec 18, 2024
1 parent def7d68 commit 8a4525e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
14 changes: 9 additions & 5 deletions lib/Db/MailAccountMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,24 @@ public function findById(int $id): MailAccount {
/**
* Finds all mail accounts by account ids
*
* @param string $userId
* @param array<int,int> $identifiers
*
* @return array<int,MailAccount>
*/
public function findByIds(array $identifiers): array {
public function findByIds(string $userId, array $identifiers): array {

Check warning on line 77 in lib/Db/MailAccountMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/MailAccountMapper.php#L77

Added line #L77 was not covered by tests

$cmd = $this->db->getQueryBuilder();
$cmd->select('*')
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$cmd->expr()->in('id', $cmd->createNamedParameter($identifiers, IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR_ARRAY)
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR), IQueryBuilder::PARAM_STR)
)
->andWhere(
$qb->expr()->in('id', $qb->createNamedParameter($identifiers, IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR_ARRAY)
);

Check warning on line 87 in lib/Db/MailAccountMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/MailAccountMapper.php#L79-L87

Added lines #L79 - L87 were not covered by tests

return $this->findEntities($cmd);
return $this->findEntities($qb);

Check warning on line 89 in lib/Db/MailAccountMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/MailAccountMapper.php#L89

Added line #L89 was not covered by tests
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ public function findMailboxAndUid(array $identifiers): array {
return [];

Check warning on line 189 in lib/Db/MessageMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/MessageMapper.php#L188-L189

Added lines #L188 - L189 were not covered by tests
}

$cmd = $this->db->getQueryBuilder();
$cmd->select('id', 'mailbox_id', 'uid')
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'mailbox_id', 'uid')
->from($this->getTableName())
->where(
$cmd->expr()->in('id', $cmd->createNamedParameter($identifiers, IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR_ARRAY)
$qb->expr()->in('id', $qb->createNamedParameter($identifiers, IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR_ARRAY)
);

Check warning on line 197 in lib/Db/MessageMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/MessageMapper.php#L192-L197

Added lines #L192 - L197 were not covered by tests

return $cmd->executeQuery()->fetchAll();
return $qb->executeQuery()->fetchAll();

Check warning on line 199 in lib/Db/MessageMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/MessageMapper.php#L199

Added line #L199 was not covered by tests

}

Expand Down
14 changes: 4 additions & 10 deletions lib/Service/MessageOperationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ protected function groupByMailbox(array $collection): array {
*
* [mailbox] to [account_id => [mailbox]]
*
* @param array<MailBox> $collection
* @param array<\OCA\Mail\Db\Mailbox> $collection
*
* @return array<int,array<MailBox>>
* @return array<int,array<\OCA\Mail\Db\Mailbox>>
*/
protected function groupByAccount(array $collection) {
return array_reduce($collection, function ($carry, $entry) {
Expand All @@ -72,7 +72,7 @@ protected function groupByAccount(array $collection) {
*
* @param array<int,bool> &$results
* @param bool $value
* @param array<MailBox> $mailboxes
* @param array<\OCA\Mail\Db\Mailbox> $mailboxes
* @param array<int,array<array{id:int,uid:int}>> $messages
*/
protected function generateResult(array &$results, bool $value, array $mailboxes, array $messages) {
Expand All @@ -99,17 +99,11 @@ public function changeFlags(string $userId, array $identifiers, array $flags): a
// retrieve all mailboxes and group by account
$mailboxes = $this->groupByAccount($this->mailboxMapper->findByIds(array_keys($messages)));

Check warning on line 100 in lib/Service/MessageOperationService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/MessageOperationService.php#L100

Added line #L100 was not covered by tests
// retrieve all accounts
$accounts = $this->accountMapper->findByIds(array_keys($mailboxes));
$accounts = $this->accountMapper->findByIds($userId, array_keys($mailboxes));

Check warning on line 102 in lib/Service/MessageOperationService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/MessageOperationService.php#L102

Added line #L102 was not covered by tests
// process every account
$results = [];
foreach ($accounts as $account) {
$account = new Account($account);
// determine if account belongs to the user and skip if not
if ($account->getUserId() != $userId) {
// add messages to results as failed
$this->generateResult($results, false, $mailboxes[$account->getId()], $messages);
continue;
}
$client = $this->clientFactory->getClient($account);

Check warning on line 107 in lib/Service/MessageOperationService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/MessageOperationService.php#L104-L107

Added lines #L104 - L107 were not covered by tests
// process every mailbox
foreach ($mailboxes[$account->getId()] as $mailbox) {

Check warning on line 109 in lib/Service/MessageOperationService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/MessageOperationService.php#L109

Added line #L109 was not covered by tests
Expand Down

0 comments on commit 8a4525e

Please sign in to comment.