Browse Source

Allow to retrieve messages without marking notifications as read

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
pull/9066/head
Marcel Müller 3 years ago
parent
commit
d480f3af4f
  1. 1
      docs/capabilities.md
  2. 20
      docs/chat.md
  3. 1
      lib/Capabilities.php
  4. 5
      lib/Chat/ChatManager.php
  5. 6
      lib/Controller/ChatController.php
  6. 1
      tests/php/CapabilitiesTest.php
  7. 4
      tests/php/Chat/ChatManagerTest.php

1
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

20
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:

1
lib/Capabilities.php

@ -116,6 +116,7 @@ class Capabilities implements IPublicCapability {
'recording-v1',
'chat-get-context',
'single-conversation-status',
'chat-keep-notifications',
],
'config' => [
'attachments' => [

5
lib/Chat/ChatManager.php

@ -598,12 +598,13 @@ class ChatManager {
* @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());
}

6
lib/Controller/ChatController.php

@ -380,6 +380,7 @@ class ChatController extends AEnvironmentAwareController {
* 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 @@ class ChatController extends AEnvironmentAwareController {
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 @@ class ChatController extends AEnvironmentAwareController {
$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);
}

1
tests/php/CapabilitiesTest.php

@ -125,6 +125,7 @@ class CapabilitiesTest extends TestCase {
'recording-v1',
'chat-get-context',
'single-conversation-status',
'chat-keep-notifications',
'message-expiration',
'reactions',
];

4
tests/php/Chat/ChatManagerTest.php

@ -347,7 +347,7 @@ class ChatManagerTest extends TestCase {
->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 @@ class ChatManagerTest extends TestCase {
->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);
}

Loading…
Cancel
Save