-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only show each thread once per message list
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
- Loading branch information
Showing
17 changed files
with
728 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @author Daniel Kesselberg <mail@danielkesselberg.de> | ||
* | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\Controller; | ||
|
||
use OCA\Mail\Contracts\IMailManager; | ||
use OCA\Mail\Db\ThreadMapper; | ||
use OCA\Mail\Exception\ClientException; | ||
use OCA\Mail\Exception\ServiceException; | ||
use OCA\Mail\Service\AccountService; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IRequest; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class ThreadController extends Controller { | ||
|
||
/** @var string */ | ||
private $currentUserId; | ||
|
||
/** @var LoggerInterface */ | ||
private $logger; | ||
|
||
/** @var AccountService */ | ||
private $accountService; | ||
|
||
/** @var IMailManager */ | ||
private $mailManager; | ||
|
||
/** @var ThreadMapper */ | ||
private $threadMapper; | ||
|
||
public function __construct(string $appName, | ||
IRequest $request, | ||
string $UserId, | ||
LoggerInterface $logger, | ||
AccountService $accountService, | ||
IMailManager $mailManager, | ||
ThreadMapper $threadMapper) { | ||
parent::__construct($appName, $request); | ||
|
||
$this->currentUserId = $UserId; | ||
$this->logger = $logger; | ||
$this->accountService = $accountService; | ||
$this->mailManager = $mailManager; | ||
$this->threadMapper = $threadMapper; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @TrapError | ||
* | ||
* @param int $id | ||
* | ||
* @return JSONResponse | ||
* @throws ClientException | ||
* @throws ServiceException | ||
*/ | ||
public function delete(int $id): JSONResponse { | ||
try { | ||
$message = $this->mailManager->getMessage($this->currentUserId, $id); | ||
$mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId()); | ||
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); | ||
} catch (DoesNotExistException $e) { | ||
return new JSONResponse([], Http::STATUS_FORBIDDEN); | ||
} | ||
|
||
$mailAccount = $account->getMailAccount(); | ||
$messageInTrash = $mailbox->getId() === $mailAccount->getTrashMailboxId(); | ||
|
||
$messages = $this->threadMapper->findMessageUidsAndMailboxNamesByAccountAndThreadRoot( | ||
$mailAccount, | ||
$message->getThreadRootId(), | ||
$messageInTrash | ||
); | ||
|
||
foreach ($messages as $message) { | ||
$this->logger->debug('deleting message', [ | ||
'messageId' => $message['messageUid'], | ||
]); | ||
|
||
$this->mailManager->deleteMessage( | ||
$account, | ||
$message['mailboxName'], | ||
$message['messageUid'] | ||
); | ||
} | ||
|
||
return new JSONResponse(); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @TrapError | ||
* | ||
* @param int $id | ||
* @param int $destMailboxId | ||
* | ||
* @return JSONResponse | ||
* @throws ClientException | ||
* @throws ServiceException | ||
*/ | ||
public function move(int $id, int $destMailboxId): JSONResponse { | ||
try { | ||
$message = $this->mailManager->getMessage($this->currentUserId, $id); | ||
$srcMailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId()); | ||
$srcAccount = $this->accountService->find($this->currentUserId, $srcMailbox->getAccountId()); | ||
$dstMailbox = $this->mailManager->getMailbox($this->currentUserId, $destMailboxId); | ||
$dstAccount = $this->accountService->find($this->currentUserId, $dstMailbox->getAccountId()); | ||
} catch (DoesNotExistException $e) { | ||
return new JSONResponse([], Http::STATUS_FORBIDDEN); | ||
} | ||
|
||
$mailAccount = $srcAccount->getMailAccount(); | ||
$messageInTrash = $srcMailbox->getId() === $mailAccount->getTrashMailboxId(); | ||
|
||
$messages = $this->threadMapper->findMessageUidsAndMailboxNamesByAccountAndThreadRoot( | ||
$mailAccount, | ||
$message->getThreadRootId(), | ||
$messageInTrash | ||
); | ||
|
||
foreach ($messages as $message) { | ||
$this->logger->debug('move message', [ | ||
'messageId' => $message['messageUid'], | ||
'destMailboxId' => $destMailboxId | ||
]); | ||
|
||
$this->mailManager->moveMessage( | ||
$srcAccount, | ||
$message['mailboxName'], | ||
$message['messageUid'], | ||
$dstAccount, | ||
$dstMailbox->getName() | ||
); | ||
} | ||
|
||
return new JSONResponse(); | ||
} | ||
} |
Oops, something went wrong.