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
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2021-06-01 21:53:19 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-06-10 12:27:59 +0300
commit0da32c97f64e0cdf950368257447ec8fa6fe7fea (patch)
treee8caddaefcb971e17a83b32e60726d8cdeac568d /lib/Controller
parentc149af8e36d5491b2a9bb0133495f289e00d6945 (diff)
Show each thread once per message list
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Controller')
-rwxr-xr-xlib/Controller/MessagesController.php2
-rwxr-xr-xlib/Controller/ThreadController.php123
2 files changed, 124 insertions, 1 deletions
diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php
index a39de7001..e3cc7a3e7 100755
--- a/lib/Controller/MessagesController.php
+++ b/lib/Controller/MessagesController.php
@@ -307,7 +307,7 @@ class MessagesController extends Controller {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
- return new JSONResponse($this->mailManager->getThread($account, $id));
+ return new JSONResponse($this->mailManager->getThread($account, $message->getThreadRootId()));
}
/**
diff --git a/lib/Controller/ThreadController.php b/lib/Controller/ThreadController.php
new file mode 100755
index 000000000..eecc245a0
--- /dev/null
+++ b/lib/Controller/ThreadController.php
@@ -0,0 +1,123 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Daniel Kesselberg <mail@danielkesselberg.de>
+ *
+ * Mail
+ *
+ * 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\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;
+
+ public function __construct(string $appName,
+ IRequest $request,
+ string $UserId,
+ AccountService $accountService,
+ IMailManager $mailManager) {
+ parent::__construct($appName, $request);
+
+ $this->currentUserId = $UserId;
+ $this->accountService = $accountService;
+ $this->mailManager = $mailManager;
+ }
+
+ /**
+ * @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);
+ }
+
+ $this->mailManager->moveThread(
+ $srcAccount,
+ $srcMailbox,
+ $dstAccount,
+ $dstMailbox,
+ $message->getThreadRootId()
+ );
+
+ return new JSONResponse();
+ }
+
+ /**
+ * @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);
+ }
+
+ $this->mailManager->deleteThread(
+ $account,
+ $mailbox,
+ $message->getThreadRootId()
+ );
+
+ return new JSONResponse();
+ }
+}