Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 11 additions & 9 deletions docs/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `markNotificationsAsRead` | int | `0` to not mark notifications as read (Default: `1`, only available with `chat-read-status` capability) |
| `markNotificationsAsRead` | int | `0` to not mark notifications as read (Default: `1`, only available with `chat-keep-notifications` capability) |


* Response:
- Status code:
Expand Down
1 change: 1 addition & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function getCapabilities(): array {
'recording-v1',
'chat-get-context',
'single-conversation-status',
'chat-keep-notifications',
],
'config' => [
'attachments' => [
Expand Down
5 changes: 3 additions & 2 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
6 changes: 4 additions & 2 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions tests/php/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function setUp(): void {
'recording-v1',
'chat-get-context',
'single-conversation-status',
'chat-keep-notifications',
'message-expiration',
'reactions',
];
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Chat/ChatManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down