-
Notifications
You must be signed in to change notification settings - Fork 314
feat: Add route to open messages via Message-ID #12632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||||||||||||||||||||||
| <?php | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| declare(strict_types=1); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||||||||||||||||||||||||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| namespace OCA\Mail\Controller; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| use OCA\Mail\Db\MailAccountMapper; | ||||||||||||||||||||||||||
| use OCA\Mail\Db\MessageMapper; | ||||||||||||||||||||||||||
| use OCA\Mail\Service\AccountService; | ||||||||||||||||||||||||||
| use OCP\AppFramework\Controller; | ||||||||||||||||||||||||||
| use OCP\AppFramework\Http\RedirectResponse; | ||||||||||||||||||||||||||
| use OCP\IRequest; | ||||||||||||||||||||||||||
| use OCP\IURLGenerator; | ||||||||||||||||||||||||||
| use OCP\IUserSession; | ||||||||||||||||||||||||||
| use Psr\Log\LoggerInterface; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| class DeepLinkController extends Controller { | ||||||||||||||||||||||||||
| private MailAccountMapper $mailAccountMapper; | ||||||||||||||||||||||||||
| private AccountService $accountService; | ||||||||||||||||||||||||||
| private MessageMapper $messageMapper; | ||||||||||||||||||||||||||
| private IURLGenerator $urlGenerator; | ||||||||||||||||||||||||||
| private IUserSession $userSession; | ||||||||||||||||||||||||||
| private LoggerInterface $logger; | ||||||||||||||||||||||||||
|
Comment on lines
+23
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public function __construct( | ||||||||||||||||||||||||||
| string $appName, | ||||||||||||||||||||||||||
| IRequest $request, | ||||||||||||||||||||||||||
| MailAccountMapper $mailAccountMapper, | ||||||||||||||||||||||||||
| AccountService $accountService, | ||||||||||||||||||||||||||
| MessageMapper $messageMapper, | ||||||||||||||||||||||||||
| IURLGenerator $urlGenerator, | ||||||||||||||||||||||||||
| IUserSession $userSession, | ||||||||||||||||||||||||||
| LoggerInterface $logger | ||||||||||||||||||||||||||
|
Comment on lines
+33
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding private/protected/public in a class constructor = shortcut to create a property with the given name and assign the value to it. |
||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||
| parent::__construct($appName, $request); | ||||||||||||||||||||||||||
| $this->mailAccountMapper = $mailAccountMapper; | ||||||||||||||||||||||||||
| $this->accountService = $accountService; | ||||||||||||||||||||||||||
| $this->messageMapper = $messageMapper; | ||||||||||||||||||||||||||
| $this->urlGenerator = $urlGenerator; | ||||||||||||||||||||||||||
| $this->userSession = $userSession; | ||||||||||||||||||||||||||
| $this->logger = $logger; | ||||||||||||||||||||||||||
|
Comment on lines
+41
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * @NoAdminRequired | ||||||||||||||||||||||||||
| * @NoCSRFRequired | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
| * @PublicPage | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a public page |
||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @param string $messageId | ||||||||||||||||||||||||||
| * @return RedirectResponse | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| public function open(string $messageId): RedirectResponse { | ||||||||||||||||||||||||||
| $user = $this->userSession->getUser(); | ||||||||||||||||||||||||||
| if ($user === null) { | ||||||||||||||||||||||||||
| return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.page.login')); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| $userId = $user->getUID(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| // Ensure formatting: Always wrapped in <> | ||||||||||||||||||||||||||
| $cleanedId = '<' . trim($messageId, '<>') . '>'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| $lightAccounts = $this->mailAccountMapper->findByUserId($userId); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| foreach ($lightAccounts as $lightAccount) { | ||||||||||||||||||||||||||
| $accountId = $lightAccount->getId(); | ||||||||||||||||||||||||||
| $account = $this->accountService->find($userId, $accountId); | ||||||||||||||||||||||||||
| $messages = $this->messageMapper->findByMessageId($account, $cleanedId); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!empty($messages)) { | ||||||||||||||||||||||||||
| $message = $messages[0]; | ||||||||||||||||||||||||||
| $targetId = $message->getId(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // IMPORTANT FIX: Use 'mail.page.thread' instead of 'mail.page#thread' | ||||||||||||||||||||||||||
| $url = $this->urlGenerator->linkToRouteAbsolute( | ||||||||||||||||||||||||||
| 'mail.page.thread', | ||||||||||||||||||||||||||
| ['mailboxId' => $message->getMailboxId(), 'id' => $targetId] | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return new RedirectResponse($url); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } catch (\Exception $e) { | ||||||||||||||||||||||||||
| $this->logger->error('DeepLinkController: An unexpected error occurred.', [ | ||||||||||||||||||||||||||
| 'exception' => $e, | ||||||||||||||||||||||||||
| 'messageId' => $messageId, | ||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Fallback | ||||||||||||||||||||||||||
| return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('mail.page.index', [])); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.