summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-03-15 15:28:53 +0100
committerJoas Schilling <coding@schilljs.com>2024-03-15 15:31:36 +0100
commit99cafa2ceb247aa5541cc80ca3b4fcbd9d07c91d (patch)
treed0f38e83c65d2f0e624162e526ce203d5301b631 /lib/Controller
parenteb45b2eb8787207d072e5399da50f24f000df658 (diff)
feat(reminders): Implement reminders for messages not in cache
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/ChatController.php35
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php
index 0b1a6bb72..c1bd4907a 100644
--- a/lib/Controller/ChatController.php
+++ b/lib/Controller/ChatController.php
@@ -31,6 +31,7 @@ use OCA\Talk\Chat\AutoComplete\Sorter;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Chat\ReactionManager;
+use OCA\Talk\Exceptions\CannotReachRemoteException;
use OCA\Talk\Federation\Authenticator;
use OCA\Talk\GuestManager;
use OCA\Talk\MatterbridgeManager;
@@ -46,7 +47,6 @@ use OCA\Talk\Model\Attachment;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\Bot;
use OCA\Talk\Model\Message;
-use OCA\Talk\Model\ProxyCacheMessageMapper;
use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\ResponseDefinitions;
@@ -55,6 +55,7 @@ use OCA\Talk\Service\AttachmentService;
use OCA\Talk\Service\AvatarService;
use OCA\Talk\Service\BotService;
use OCA\Talk\Service\ParticipantService;
+use OCA\Talk\Service\ProxyCacheMessageService;
use OCA\Talk\Service\ReminderService;
use OCA\Talk\Service\RoomFormatter;
use OCA\Talk\Service\SessionService;
@@ -128,7 +129,7 @@ class ChatController extends AEnvironmentAwareController {
protected ITrustedDomainHelper $trustedDomainHelper,
private IL10N $l,
protected Authenticator $federationAuthenticator,
- protected ProxyCacheMessageMapper $proxyCacheMapper,
+ protected ProxyCacheMessageService $pcmService,
) {
parent::__construct($appName, $request);
}
@@ -916,7 +917,7 @@ class ChatController extends AEnvironmentAwareController {
* @psalm-param non-negative-int $messageId
* @param int $timestamp Timestamp of the reminder
* @psalm-param non-negative-int $timestamp
- * @return DataResponse<Http::STATUS_CREATED, TalkChatReminder, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
+ * @return DataResponse<Http::STATUS_CREATED, TalkChatReminder, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{error?: string}, array{}>
*
* 201: Reminder created successfully
* 404: Message not found
@@ -928,9 +929,9 @@ class ChatController extends AEnvironmentAwareController {
#[UserRateLimit(limit: 60, period: 3600)]
public function setReminder(int $messageId, int $timestamp): DataResponse {
try {
- $this->validateMessageExists($messageId);
+ $this->validateMessageExists($messageId, sync: true);
} catch (DoesNotExistException) {
- return new DataResponse([], Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'message'], Http::STATUS_NOT_FOUND);
}
$reminder = $this->reminderService->setReminder(
@@ -948,7 +949,7 @@ class ChatController extends AEnvironmentAwareController {
*
* @param int $messageId ID of the message
* @psalm-param non-negative-int $messageId
- * @return DataResponse<Http::STATUS_OK, TalkChatReminder, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
+ * @return DataResponse<Http::STATUS_OK, TalkChatReminder, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{error?: string}, array{}>
*
* 200: Reminder returned
* 404: No reminder found
@@ -962,7 +963,7 @@ class ChatController extends AEnvironmentAwareController {
try {
$this->validateMessageExists($messageId);
} catch (DoesNotExistException) {
- return new DataResponse([], Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'message'], Http::STATUS_NOT_FOUND);
}
try {
@@ -973,7 +974,7 @@ class ChatController extends AEnvironmentAwareController {
);
return new DataResponse($reminder->jsonSerialize(), Http::STATUS_OK);
} catch (DoesNotExistException) {
- return new DataResponse([], Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'reminder'], Http::STATUS_NOT_FOUND);
}
}
@@ -982,7 +983,7 @@ class ChatController extends AEnvironmentAwareController {
*
* @param int $messageId ID of the message
* @psalm-param non-negative-int $messageId
- * @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, array<empty>, array{}>
+ * @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, array{error?: string}, array{}>
*
* 200: Reminder deleted successfully
* 404: Message not found
@@ -995,7 +996,7 @@ class ChatController extends AEnvironmentAwareController {
try {
$this->validateMessageExists($messageId);
} catch (DoesNotExistException) {
- return new DataResponse([], Http::STATUS_NOT_FOUND);
+ return new DataResponse(['error' => 'message'], Http::STATUS_NOT_FOUND);
}
$this->reminderService->deleteReminder(
@@ -1007,9 +1008,19 @@ class ChatController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_OK);
}
- protected function validateMessageExists(int $messageId): void {
+ /**
+ * @throws DoesNotExistException
+ * @throws CannotReachRemoteException
+ */
+ protected function validateMessageExists(int $messageId, bool $sync = false): void {
if ($this->room->isFederatedConversation()) {
- $this->proxyCacheMapper->findByRemote($this->room->getRemoteServer(), $this->room->getRemoteToken(), $messageId);
+ try {
+ $this->pcmService->findByRemote($this->room->getRemoteServer(), $this->room->getRemoteToken(), $messageId);
+ } catch (DoesNotExistException) {
+ if ($sync) {
+ $this->pcmService->syncRemoteMessage($this->room, $this->participant, $messageId);
+ }
+ }
return;
}