diff --git a/docs/chat.md b/docs/chat.md index 7280253e79d..161aceb1860 100644 --- a/docs/chat.md +++ b/docs/chat.md @@ -351,6 +351,7 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob ## Set reminder for chat message * Required capability: `remind-me-later` +* Federation capability: `federation-v1` * Method: `POST` * Endpoint: `/chat/{token}/{messageId}/reminder` * Data: @@ -379,6 +380,7 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob ## Get reminder for chat message * Required capability: `remind-me-later` +* Federation capability: `federation-v1` * Method: `GET` * Endpoint: `/chat/{token}/{messageId}/reminder` @@ -403,6 +405,7 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob ## Delete reminder for chat message * Required capability: `remind-me-later` +* Federation capability: `federation-v1` * Method: `DELETE` * Endpoint: `/chat/{token}/{messageId}/reminder` diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index bad6ee7ea7e..c1bd4907ada 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -31,6 +31,7 @@ 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; @@ -54,6 +55,7 @@ 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; @@ -127,6 +129,7 @@ public function __construct( protected ITrustedDomainHelper $trustedDomainHelper, private IL10N $l, protected Authenticator $federationAuthenticator, + protected ProxyCacheMessageService $pcmService, ) { parent::__construct($appName, $request); } @@ -914,20 +917,21 @@ public function editMessage(int $messageId, string $message): DataResponse { * @psalm-param non-negative-int $messageId * @param int $timestamp Timestamp of the reminder * @psalm-param non-negative-int $timestamp - * @return DataResponse|DataResponse, array{}> + * @return DataResponse|DataResponse * * 201: Reminder created successfully * 404: Message not found */ + #[FederationSupported] #[NoAdminRequired] #[RequireModeratorOrNoLobby] #[RequireLoggedInParticipant] #[UserRateLimit(limit: 60, period: 3600)] public function setReminder(int $messageId, int $timestamp): DataResponse { try { - $this->chatManager->getComment($this->room, (string) $messageId); - } catch (NotFoundException) { - return new DataResponse([], Http::STATUS_NOT_FOUND); + $this->validateMessageExists($messageId, sync: true); + } catch (DoesNotExistException) { + return new DataResponse(['error' => 'message'], Http::STATUS_NOT_FOUND); } $reminder = $this->reminderService->setReminder( @@ -945,30 +949,32 @@ public function setReminder(int $messageId, int $timestamp): DataResponse { * * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId - * @return DataResponse|DataResponse, array{}> + * @return DataResponse|DataResponse * * 200: Reminder returned * 404: No reminder found * 404: Message not found */ + #[FederationSupported] #[NoAdminRequired] #[RequireModeratorOrNoLobby] #[RequireLoggedInParticipant] public function getReminder(int $messageId): DataResponse { try { - $this->chatManager->getComment($this->room, (string) $messageId); - } catch (NotFoundException) { - return new DataResponse([], Http::STATUS_NOT_FOUND); + $this->validateMessageExists($messageId); + } catch (DoesNotExistException) { + return new DataResponse(['error' => 'message'], Http::STATUS_NOT_FOUND); } try { $reminder = $this->reminderService->getReminder( $this->participant->getAttendee()->getActorId(), + $this->room->getToken(), $messageId, ); 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); } } @@ -977,19 +983,20 @@ public function getReminder(int $messageId): DataResponse { * * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId - * @return DataResponse, array{}> + * @return DataResponse * * 200: Reminder deleted successfully * 404: Message not found */ + #[FederationSupported] #[NoAdminRequired] #[RequireModeratorOrNoLobby] #[RequireLoggedInParticipant] public function deleteReminder(int $messageId): DataResponse { try { - $this->chatManager->getComment($this->room, (string) $messageId); - } catch (NotFoundException) { - return new DataResponse([], Http::STATUS_NOT_FOUND); + $this->validateMessageExists($messageId); + } catch (DoesNotExistException) { + return new DataResponse(['error' => 'message'], Http::STATUS_NOT_FOUND); } $this->reminderService->deleteReminder( @@ -1001,6 +1008,29 @@ public function deleteReminder(int $messageId): DataResponse { return new DataResponse([], Http::STATUS_OK); } + /** + * @throws DoesNotExistException + * @throws CannotReachRemoteException + */ + protected function validateMessageExists(int $messageId, bool $sync = false): void { + if ($this->room->isFederatedConversation()) { + try { + $this->pcmService->findByRemote($this->room->getRemoteServer(), $this->room->getRemoteToken(), $messageId); + } catch (DoesNotExistException) { + if ($sync) { + $this->pcmService->syncRemoteMessage($this->room, $this->participant, $messageId); + } + } + return; + } + + try { + $this->chatManager->getComment($this->room, (string)$messageId); + } catch (NotFoundException $e) { + throw new DoesNotExistException($e->getMessage()); + } + } + /** * Clear the chat history * diff --git a/lib/Manager.php b/lib/Manager.php index b9a81c65e96..5b6f7c1838d 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -882,6 +882,28 @@ public function getMultipleRoomsByObject(string $objectType, string $objectId, b return $rooms; } + /** + * @param string[] $tokens + * @return array + */ + public function getRoomsByToken(array $tokens): array { + $query = $this->db->getQueryBuilder(); + $helper = new SelectHelper(); + $helper->selectRoomsTable($query); + $query->from('talk_rooms', 'r') + ->where($query->expr()->in('r.token', $query->createNamedParameter($tokens, IQueryBuilder::PARAM_STR_ARRAY))); + + $result = $query->executeQuery(); + $rooms = []; + while ($row = $result->fetch()) { + $room = $this->createRoomObject($row); + $rooms[$room->getToken()] = $room; + } + $result->closeCursor(); + + return $rooms; + } + /** * @param string|null $userId * @param string|null $sessionId diff --git a/lib/Model/ReminderMapper.php b/lib/Model/ReminderMapper.php index 51fada9b90f..c14a9273f17 100644 --- a/lib/Model/ReminderMapper.php +++ b/lib/Model/ReminderMapper.php @@ -49,11 +49,12 @@ public function __construct( /** * @throws DoesNotExistException */ - public function findForUserAndMessage(string $userId, int $messageId): Reminder { + public function findForUserAndMessage(string $userId, string $token, int $messageId): Reminder { $query = $this->db->getQueryBuilder(); $query->select('*') ->from($this->getTableName()) ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) + ->andWhere($query->expr()->eq('token', $query->createNamedParameter($token, IQueryBuilder::PARAM_STR))) ->andWhere($query->expr()->eq('message_id', $query->createNamedParameter($messageId, IQueryBuilder::PARAM_INT))); return $this->findEntity($query); diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 7896ac6cf2d..88e93aa6462 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -625,7 +625,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par 'name' => $shortenMessage, ]; if ($notification->getSubject() === 'reminder') { - if ($comment->getActorId() === $notification->getUser()) { + if ($message->getActorId() === $notification->getUser()) { // TRANSLATORS Reminder for a message you sent in the conversation {call} $subject = $l->t('Reminder: You in {call}') . "\n{message}"; } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { @@ -716,7 +716,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par } } elseif ($notification->getSubject() === 'reminder') { if ($room->getType() === Room::TYPE_ONE_TO_ONE || $room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { - if ($comment->getActorId() === $notification->getUser()) { + if ($message->getActorId() === $notification->getUser()) { $subject = $l->t('Reminder: You in private conversation {call}'); } elseif ($room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) { $subject = $l->t('Reminder: A deleted user in private conversation {call}'); @@ -724,7 +724,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par $subject = $l->t('Reminder: {user} in private conversation'); } } elseif ($richSubjectUser) { - if ($comment->getActorId() === $notification->getUser()) { + if ($message->getActorId() === $notification->getUser()) { $subject = $l->t('Reminder: You in conversation {call}'); } else { $subject = $l->t('Reminder: {user} in conversation {call}'); diff --git a/lib/Service/ProxyCacheMessageService.php b/lib/Service/ProxyCacheMessageService.php new file mode 100644 index 00000000000..a7ebb1c8e03 --- /dev/null +++ b/lib/Service/ProxyCacheMessageService.php @@ -0,0 +1,128 @@ + + * + * @author Joas Schilling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace OCA\Talk\Service; + +use OCA\Talk\Exceptions\CannotReachRemoteException; +use OCA\Talk\Model\Message; +use OCA\Talk\Model\ProxyCacheMessage; +use OCA\Talk\Model\ProxyCacheMessageMapper; +use OCA\Talk\Participant; +use OCA\Talk\ResponseDefinitions; +use OCA\Talk\Room; +use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Http; +use OCP\DB\Exception as DBException; +use Psr\Log\LoggerInterface; + +/** + * @psalm-import-type TalkChatMessageWithParent from ResponseDefinitions + */ +class ProxyCacheMessageService { + public function __construct( + protected ProxyCacheMessageMapper $mapper, + protected LoggerInterface $logger, + ) { + } + + /** + * @throws DoesNotExistException + */ + public function findByRemote(string $remoteServerUrl, string $remoteToken, int $remoteMessageId): ProxyCacheMessage { + return $this->mapper->findByRemote($remoteServerUrl, $remoteToken, $remoteMessageId); + } + + /** + * @throws \InvalidArgumentException + * @throws CannotReachRemoteException + */ + public function syncRemoteMessage(Room $room, Participant $participant, int $messageId): ProxyCacheMessage { + if (!$room->isFederatedConversation()) { + throw new \InvalidArgumentException('room'); + } + + /** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */ + $proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class); + $ocsResponse = $proxy->getMessageContext($room, $participant, $messageId, 1); + + if ($ocsResponse->getStatus() !== Http::STATUS_OK || !isset($ocsResponse->getData()[0])) { + throw new \InvalidArgumentException('message'); + } + + /** @var TalkChatMessageWithParent $messageData */ + $messageData = $ocsResponse->getData()[0]; + + $proxy = new ProxyCacheMessage(); + $proxy->setLocalToken($room->getToken()); + $proxy->setRemoteServerUrl($room->getRemoteServer()); + $proxy->setRemoteToken($room->getRemoteToken()); + $proxy->setRemoteMessageId($messageData['id']); + $proxy->setActorType($messageData['actorType']); + $proxy->setActorId($messageData['actorId']); + $proxy->setActorDisplayName($messageData['actorDisplayName']); + $proxy->setMessageType($messageData['messageType']); + $proxy->setSystemMessage($messageData['systemMessage']); + if ($messageData['expirationTimestamp']) { + $proxy->setExpirationDatetime(new \DateTime('@' . $messageData['expirationTimestamp'])); + } + $proxy->setCreationDatetime(new \DateTime('@' . $messageData['timestamp'])); + $proxy->setMessage($messageData['message']); + $proxy->setMessageParameters(json_encode($messageData['messageParameters'])); + + $metaData = []; + if (!empty($messageData['lastEditActorType']) && !empty($messageData['lastEditActorId'])) { + $metaData[Message::METADATA_LAST_EDITED_BY_TYPE] = $messageData['lastEditActorType']; + $metaData[Message::METADATA_LAST_EDITED_BY_ID] = $messageData['lastEditActorId']; + } + if (!empty($messageData['lastEditTimestamp'])) { + $metaData[Message::METADATA_LAST_EDITED_TIME] = $messageData['lastEditTimestamp']; + } + if (!empty($messageData['silent'])) { + $metaData[Message::METADATA_SILENT] = $messageData['silent']; + } + $proxy->setMetaData(json_encode($metaData)); + + try { + $this->mapper->insert($proxy); + } catch (DBException $e) { + // DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION happens when + // multiple users are in the same conversation. We are therefore + // informed multiple times about the same remote message. + if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) { + $this->logger->error('Error saving proxy cache message failed: ' . $e->getMessage(), ['exception' => $e]); + throw $e; + } + + $proxy = $this->mapper->findByRemote( + $room->getRemoteServer(), + $room->getRemoteToken(), + $messageData['id'], + ); + } + + return $proxy; + } +} diff --git a/lib/Service/ReminderService.php b/lib/Service/ReminderService.php index f88bbdf36a8..13396b3b88a 100644 --- a/lib/Service/ReminderService.php +++ b/lib/Service/ReminderService.php @@ -28,6 +28,8 @@ use OCA\Talk\AppInfo\Application; use OCA\Talk\Chat\ChatManager; +use OCA\Talk\Manager; +use OCA\Talk\Model\ProxyCacheMessage; use OCA\Talk\Model\Reminder; use OCA\Talk\Model\ReminderMapper; use OCP\AppFramework\Db\DoesNotExistException; @@ -38,12 +40,14 @@ public function __construct( protected IManager $notificationManager, protected ReminderMapper $reminderMapper, protected ChatManager $chatManager, + protected ProxyCacheMessageService $pcmService, + protected Manager $manager, ) { } public function setReminder(string $userId, string $token, int $messageId, int $timestamp): Reminder { try { - $reminder = $this->reminderMapper->findForUserAndMessage($userId, $messageId); + $reminder = $this->reminderMapper->findForUserAndMessage($userId, $token, $messageId); $reminder->setDateTime(new \DateTime('@' . $timestamp)); $this->reminderMapper->update($reminder); @@ -62,13 +66,13 @@ public function setReminder(string $userId, string $token, int $messageId, int $ /** * @throws DoesNotExistException */ - public function getReminder(string $userId, int $messageId): Reminder { - return $this->reminderMapper->findForUserAndMessage($userId, $messageId); + public function getReminder(string $userId, string $token, int $messageId): Reminder { + return $this->reminderMapper->findForUserAndMessage($userId, $token, $messageId); } public function deleteReminder(string $userId, string $token, int $messageId): void { try { - $reminder = $this->reminderMapper->findForUserAndMessage($userId, $messageId); + $reminder = $this->reminderMapper->findForUserAndMessage($userId, $token, $messageId); $this->reminderMapper->delete($reminder); } catch (DoesNotExistException) { // When the reminder does not exist anymore, the notification could be there @@ -92,19 +96,59 @@ public function executeReminders(\DateTime $executeBefore): void { $shouldFlush = $this->notificationManager->defer(); + $roomTokens = []; + foreach ($reminders as $reminder) { + $roomTokens[] = $reminder->getToken(); + } + $roomTokens = array_unique($roomTokens); + $rooms = $this->manager->getRoomsByToken($roomTokens); + + /** @var array $proxyMessages */ + $proxyMessages = []; $messageIds = []; foreach ($reminders as $reminder) { - $messageIds[] = $reminder->getMessageId(); + if (!isset($rooms[$reminder->getToken()])) { + continue; + } + + $room = $rooms[$reminder->getToken()]; + if (!$room->isFederatedConversation()) { + $messageIds[] = $reminder->getMessageId(); + } else { + $key = json_encode([$room->getRemoteServer(), $room->getRemoteToken(), $reminder->getMessageId()]); + if (!isset($proxyMessages[$key])) { + try { + $proxyMessages[$key] = $this->pcmService->findByRemote($room->getRemoteServer(), $room->getRemoteToken(), $reminder->getMessageId()); + } catch (DoesNotExistException) { + } + } + } } + $messageIds = array_unique($messageIds); $messages = $this->chatManager->getMessagesById($messageIds); foreach ($reminders as $reminder) { - if (!isset($messages[$reminder->getMessageId()])) { + $room = $rooms[$reminder->getToken()]; + if (!$room->isFederatedConversation()) { + $key = $reminder->getMessageId(); + $messageList = $messages; + $messageParameters = [ + 'commentId' => $reminder->getMessageId(), + ]; + } else { + $key = json_encode([$room->getRemoteServer(), $room->getRemoteToken(), $reminder->getMessageId()]); + $messageList = $proxyMessages; + $messageParameters = [ + 'proxyId' => $messageList[$key]?->getId(), + ]; + } + + if (!isset($messageList[$key])) { continue; } - $message = $messages[$reminder->getMessageId()]; + $message = $messageList[$key]; $notification = $this->notificationManager->createNotification(); $notification->setApp(Application::APP_ID) @@ -117,9 +161,7 @@ public function executeReminders(\DateTime $executeBefore): void { 'userType' => $message->getActorType(), 'userId' => $message->getActorId(), ]) - ->setMessage('reminder', [ - 'commentId' => $reminder->getMessageId(), - ]); + ->setMessage('reminder', $messageParameters); $this->notificationManager->notify($notification); } diff --git a/lib/Service/RoomFormatter.php b/lib/Service/RoomFormatter.php index 1f6fee7b747..f92d1413a64 100644 --- a/lib/Service/RoomFormatter.php +++ b/lib/Service/RoomFormatter.php @@ -31,7 +31,6 @@ use OCA\Talk\Federation\Proxy\TalkV1\UserConverter; use OCA\Talk\Model\Attendee; use OCA\Talk\Model\BreakoutRoom; -use OCA\Talk\Model\ProxyCacheMessageMapper; use OCA\Talk\Model\Session; use OCA\Talk\Participant; use OCA\Talk\ResponseDefinitions; @@ -64,7 +63,7 @@ public function __construct( protected IAppManager $appManager, protected IManager $userStatusManager, protected IUserManager $userManager, - protected ProxyCacheMessageMapper $proxyCacheMessageMapper, + protected ProxyCacheMessageService $pcmService, protected UserConverter $userConverter, protected IL10N $l10n, protected ?string $userId, @@ -390,7 +389,7 @@ public function formatRoomV4( } elseif ($room->getRemoteServer() !== '') { $roomData['lastCommonReadMessage'] = 0; try { - $cachedMessage = $this->proxyCacheMessageMapper->findByRemote( + $cachedMessage = $this->pcmService->findByRemote( $room->getRemoteServer(), $room->getRemoteToken(), $room->getLastMessageId(), diff --git a/openapi-full.json b/openapi-full.json index cec04ca5716..d65693ed2b3 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -6108,7 +6108,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } @@ -6227,7 +6234,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } @@ -6316,7 +6330,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } @@ -6344,7 +6365,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } diff --git a/openapi.json b/openapi.json index 93fb28bc7bd..f1cc7f89f87 100644 --- a/openapi.json +++ b/openapi.json @@ -5995,7 +5995,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } @@ -6114,7 +6121,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } @@ -6203,7 +6217,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } @@ -6231,7 +6252,14 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } } } } diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index 69a13e521a4..3a7fbf37ca6 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -2376,7 +2376,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; @@ -2419,7 +2421,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; @@ -2447,7 +2451,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; @@ -2458,7 +2464,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index ace0b2c0586..846a56ce411 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -2207,7 +2207,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; @@ -2250,7 +2252,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; @@ -2278,7 +2282,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; @@ -2289,7 +2295,9 @@ export type operations = { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: unknown; + data: { + error?: string; + }; }; }; }; diff --git a/tests/integration/features/federation/chat.feature b/tests/integration/features/federation/chat.feature index b56078ce27a..3afb77b6f99 100644 --- a/tests/integration/features/federation/chat.feature +++ b/tests/integration/features/federation/chat.feature @@ -175,19 +175,12 @@ Feature: federation/chat | roomType | 2 | | roomName | room | And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4) - And user "participant1" adds federated_user "participant3" to room "room" with 200 (v4) And user "participant2" has the following invitations (v1) | remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName | | LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname | And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1) | id | name | type | remoteServer | remoteToken | | room | room | 2 | LOCAL | room | - And user "participant3" has the following invitations (v1) - | remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName | - | LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname | - And user "participant3" accepts invite to room "room" of server "LOCAL" with 200 (v1) - | id | name | type | remoteServer | remoteToken | - | room | room | 2 | LOCAL | room | Then user "participant2" is participant of the following rooms (v4) | id | type | | room | 2 | diff --git a/tests/integration/features/federation/reminder.feature b/tests/integration/features/federation/reminder.feature new file mode 100644 index 00000000000..5e30035c4f8 --- /dev/null +++ b/tests/integration/features/federation/reminder.feature @@ -0,0 +1,75 @@ +Feature: federation/chat + Background: + Given user "participant1" exists + Given user "participant2" exists + Given user "participant3" exists + + Scenario: Get mention suggestions (translating local users to federated users) + Given the following "spreed" app config is set + | federation_enabled | yes | + Given user "participant1" creates room "room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" sends message "Message 1" to room "room" with 201 + And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4) + And user "participant2" has the following invitations (v1) + | remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName | + | LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname | + And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1) + | id | name | type | remoteServer | remoteToken | + | room | room | 2 | LOCAL | room | + Then user "participant2" is participant of the following rooms (v4) + | id | type | + | room | 2 | + And user "participant2" joins room "LOCAL::room" with 200 (v4) + And user "participant2" leaves room "LOCAL::room" with 200 (v4) + And user "participant2" sends message "Message 2" to room "LOCAL::room" with 201 + When user "participant1" sets reminder for message "Message 2" in room "room" for time 2133349024 with 201 (v1) + And user "participant2" sets reminder for message "Message 1" in room "LOCAL::room" for time 1234567 with 201 (v1) + And user "participant1" has the following notifications + | app | object_type | object_id | subject | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + And force run "OCA\Talk\BackgroundJob\Reminder" background jobs + Then user "participant1" has the following notifications + | app | object_type | object_id | subject | + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 1 | Reminder: participant1-displayname in conversation room | + # Participant1 sets timestamp to past so it should trigger now + When user "participant1" sets reminder for message "Message 2" in room "room" for time 1234567 with 201 (v1) + And force run "OCA\Talk\BackgroundJob\Reminder" background jobs + Then user "participant1" has the following notifications + | app | object_type | object_id | subject | + | spreed | reminder | room/Message 2 | Reminder: participant2-displayname in conversation room | + And user "participant2" deletes reminder for message "Message 1" in room "LOCAL::room" with 200 (v1) + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + + Scenario: Deleting reminder before the job is executed never triggers a notification + Given the following "spreed" app config is set + | federation_enabled | yes | + Given user "participant1" creates room "room" (v4) + | roomType | 2 | + | roomName | room | + And user "participant1" sends message "Message 1" to room "room" with 201 + And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4) + And user "participant1" adds user "participant3" to room "room" with 200 (v4) + And user "participant2" has the following invitations (v1) + | remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName | + | LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname | + And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1) + | id | name | type | remoteServer | remoteToken | + | room | room | 2 | LOCAL | room | + Then user "participant2" is participant of the following rooms (v4) + | id | type | + | room | 2 | + And user "participant2" joins room "LOCAL::room" with 200 (v4) + And user "participant2" leaves room "LOCAL::room" with 200 (v4) + When user "participant2" sets reminder for message "Message 1" in room "LOCAL::room" for time 1234567 with 201 (v1) + And user "participant2" deletes reminder for message "Message 1" in room "LOCAL::room" with 200 (v1) + And user "participant2" has the following notifications + | app | object_type | object_id | subject | + And force run "OCA\Talk\BackgroundJob\Reminder" background jobs + And user "participant2" has the following notifications + | app | object_type | object_id | subject | diff --git a/tests/php/Controller/ChatControllerTest.php b/tests/php/Controller/ChatControllerTest.php index 1135bc9368f..76147899cae 100644 --- a/tests/php/Controller/ChatControllerTest.php +++ b/tests/php/Controller/ChatControllerTest.php @@ -39,6 +39,7 @@ 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; @@ -115,6 +116,7 @@ class ChatControllerTest extends TestCase { /** @var IL10N|MockObject */ private $l; private Authenticator|MockObject $federationAuthenticator; + private ProxyCacheMessageService|MockObject $pcmService; /** @var Room|MockObject */ protected $room; @@ -154,6 +156,7 @@ public function setUp(): void { $this->trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); $this->l = $this->createMock(IL10N::class); $this->federationAuthenticator = $this->createMock(Authenticator::class); + $this->pcmService = $this->createMock(ProxyCacheMessageService::class); $this->room = $this->createMock(Room::class); @@ -198,6 +201,7 @@ private function recreateChatController() { $this->trustedDomainHelper, $this->l, $this->federationAuthenticator, + $this->pcmService, ); }