diff --git a/docs/capabilities.md b/docs/capabilities.md index 1c1b52221a8..61f0a041a8d 100644 --- a/docs/capabilities.md +++ b/docs/capabilities.md @@ -111,3 +111,4 @@ * `config => call => breakout-rooms` - Whether breakout rooms are enabled on this instance * `config => call => recording` - Whether calls can be recorded (requires the High-performance backend server) * `single-conversation-status` - When the response of a single conversation can also return the user status +* `chat-keep-notifications` - Whether messages can be retrieved without marking notifications as read diff --git a/docs/chat.md b/docs/chat.md index 4de385b0078..548a0905fc2 100644 --- a/docs/chat.md +++ b/docs/chat.md @@ -14,15 +14,17 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`: since Nextcloud 13 * Endpoint: `/chat/{token}` * Data: -| field | type | Description | -|----------------------|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `lookIntoFuture` | int | `1` Poll and wait for new message or `0` get history of a conversation | -| `limit` | int | Number of chat messages to receive (100 by default, 200 at most) | -| `lastKnownMessageId` | int | Serves as an offset for the query. The lastKnownMessageId for the next page is available in the `X-Chat-Last-Given` header. | -| `lastCommonReadId` | int | Send the last `X-Chat-Last-Common-Read` header you got, if you are interested in updates of the common read value. A 304 response does not allow custom headers and otherwise the server can not know if your value is modified or not. | -| `timeout` | int | `$lookIntoFuture = 1` only, Number of seconds to wait for new messages (30 by default, 60 at most) | -| `setReadMarker` | int | `1` to automatically set the read timer after fetching the messages, use `0` when your client calls `Mark chat as read` manually. (Default: `1`) | -| `includeLastKnown` | int | `1` to include the last known message as well (Default: `0`) | +| field | type | Description | +|---------------------------|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `lookIntoFuture` | int | `1` Poll and wait for new message or `0` get history of a conversation | +| `limit` | int | Number of chat messages to receive (100 by default, 200 at most) | +| `lastKnownMessageId` | int | Serves as an offset for the query. The lastKnownMessageId for the next page is available in the `X-Chat-Last-Given` header. | +| `lastCommonReadId` | int | Send the last `X-Chat-Last-Common-Read` header you got, if you are interested in updates of the common read value. A 304 response does not allow custom headers and otherwise the server can not know if your value is modified or not. | +| `timeout` | int | `$lookIntoFuture = 1` only, Number of seconds to wait for new messages (30 by default, 60 at most) | +| `setReadMarker` | int | `1` to automatically set the read timer after fetching the messages, use `0` when your client calls `Mark chat as read` manually. (Default: `1`) | +| `includeLastKnown` | int | `1` to include the last known message as well (Default: `0`) | +| `noStatusUpdate` | int | Whether the "online" user status of the current user should be "kept-alive" (`1`) or not (`0`) (defaults to `0`) | +| `markNotificationsAsRead` | int | `0` to not mark notifications as read (Default: `1`, only available with `chat-read-status` capability) | * Response: - Status code: diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 10730ffe7af..0e7968afb8b 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -116,6 +116,7 @@ public function getCapabilities(): array { 'recording-v1', 'chat-get-context', 'single-conversation-status', + 'chat-keep-notifications', ], 'config' => [ 'attachments' => [ diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 2e057b2e79c..eb3222130f1 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -598,12 +598,13 @@ public function getPreviousMessageWithVerb(Room $chat, int $offset, array $verbs * @param int $timeout * @param IUser|null $user * @param bool $includeLastKnown + * @param bool $markNotificationsAsRead (defaults to true) * @return IComment[] the messages found (only the id, actor type and id, * creation date and message are relevant), or an empty array if the * timeout expired. */ - public function waitForNewMessages(Room $chat, int $offset, int $limit, int $timeout, ?IUser $user, bool $includeLastKnown): array { - if ($user instanceof IUser) { + public function waitForNewMessages(Room $chat, int $offset, int $limit, int $timeout, ?IUser $user, bool $includeLastKnown, bool $markNotificationsAsRead = true): array { + if ($markNotificationsAsRead && $user instanceof IUser) { $this->notifier->markMentionNotificationsRead($chat, $user->getUID()); } diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 7ed27684dc0..151ca6b65b5 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -380,6 +380,7 @@ protected function preloadShares(array $comments): void { * if your client does this itself via chat/{token}/read set to 0 * @param int $includeLastKnown Include the $lastKnownMessageId in the messages when 1 (default 0) * @param int $noStatusUpdate When the user status should not be automatically set to online set to 1 (default 0) + * @param int $markNotificationsAsRead Set to 0 when notifications should not be marked as read (default 1) * @return DataResponse an array of chat messages, "404 Not found" if the * room token was not valid or "304 Not modified" if there were no messages; * each chat message is an array with @@ -394,7 +395,8 @@ public function receiveMessages(int $lookIntoFuture, int $timeout = 30, int $setReadMarker = 1, int $includeLastKnown = 0, - int $noStatusUpdate = 0): DataResponse { + int $noStatusUpdate = 0, + int $markNotificationsAsRead = 1): DataResponse { $limit = min(200, $limit); $timeout = min(30, $timeout); @@ -443,7 +445,7 @@ public function receiveMessages(int $lookIntoFuture, $currentUser = $this->userManager->get($this->userId); if ($lookIntoFuture) { - $comments = $this->chatManager->waitForNewMessages($this->room, $lastKnownMessageId, $limit, $timeout, $currentUser, (bool)$includeLastKnown); + $comments = $this->chatManager->waitForNewMessages($this->room, $lastKnownMessageId, $limit, $timeout, $currentUser, (bool)$includeLastKnown, (bool)$markNotificationsAsRead); } else { $comments = $this->chatManager->getHistory($this->room, $lastKnownMessageId, $limit, (bool)$includeLastKnown); } diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php index 85f3083720f..adc197887a9 100644 --- a/tests/php/CapabilitiesTest.php +++ b/tests/php/CapabilitiesTest.php @@ -125,6 +125,7 @@ public function setUp(): void { 'recording-v1', 'chat-get-context', 'single-conversation-status', + 'chat-keep-notifications', 'message-expiration', 'reactions', ]; diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php index 5ae6955e555..e0f3c9dd786 100644 --- a/tests/php/Chat/ChatManagerTest.php +++ b/tests/php/Chat/ChatManagerTest.php @@ -347,7 +347,7 @@ public function testWaitForNewMessages(): void { ->method('getUID') ->willReturn('userId'); - $comments = $this->chatManager->waitForNewMessages($chat, $offset, $limit, $timeout, $user, false); + $comments = $this->chatManager->waitForNewMessages($chat, $offset, $limit, $timeout, $user, false, true); $this->assertEquals($expected, $comments); } @@ -385,7 +385,7 @@ public function testWaitForNewMessagesWithWaiting(): void { ->method('getUID') ->willReturn('userId'); - $comments = $this->chatManager->waitForNewMessages($chat, $offset, $limit, $timeout, $user, false); + $comments = $this->chatManager->waitForNewMessages($chat, $offset, $limit, $timeout, $user, false, true); $this->assertEquals($expected, $comments); }