Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chat): Allow marking chat as read without a last message ID #11724

Merged
merged 1 commit into from
Mar 5, 2024
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 @@ -143,3 +143,4 @@
* `delete-messages-unlimited` - Whether messages can be deleted at any time (used to be restricted to 6 hours after posting)
* `edit-messages` - Whether messages can be edited (restricted to 24 hours after posting)
* `silent-send-state` - Whether messages contain a flag that they were sent silently
* `chat-read-last` - Whether chat can be marked read without giving a message ID (will fall back to the conversations last message ID)
6 changes: 3 additions & 3 deletions docs/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob
* Endpoint: `/chat/{token}/read`
* Data:

| field | type | Description |
|-------------------|------|--------------------------|
| `lastReadMessage` | int | The last read message ID |
| field | type | Description |
|-------------------|----------|----------------------------------------------------------------------|
| `lastReadMessage` | int/null | The last read message ID (Optional with `chat-read-last` 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 @@ -139,6 +139,7 @@ public function getCapabilities(): array {
'delete-messages-unlimited',
'edit-messages',
'silent-send-state',
'chat-read-last',
],
'config' => [
'attachments' => [
Expand Down
7 changes: 4 additions & 3 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,22 +1046,23 @@ public function clearHistory(): DataResponse {
/**
* Set the read marker to a specific message
*
* @param int $lastReadMessage ID if the last read message
* @psalm-param non-negative-int $lastReadMessage
* @param int|null $lastReadMessage ID if the last read message (Optional only with `chat-read-last` capability)
* @psalm-param non-negative-int|null $lastReadMessage
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{X-Chat-Last-Common-Read?: numeric-string}>
*
* 200: Read marker set successfully
*/
#[FederationSupported]
#[PublicPage]
#[RequireAuthenticatedParticipant]
public function setReadMarker(int $lastReadMessage): DataResponse {
public function setReadMarker(?int $lastReadMessage = null): DataResponse {
if ($this->room->getRemoteServer() !== '') {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->setReadMarker($this->room, $this->participant, $this->getResponseFormat(), $lastReadMessage);
}

$lastReadMessage = $lastReadMessage ?? $this->room->getLastMessageId();
$this->participantService->updateLastReadMessage($this->participant, $lastReadMessage);
$attendee = $this->participant->getAttendee();

Expand Down
4 changes: 2 additions & 2 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6266,11 +6266,11 @@
{
"name": "lastReadMessage",
"in": "query",
"description": "ID if the last read message",
"required": true,
"description": "ID if the last read message (Optional only with `chat-read-last` capability)",
"schema": {
"type": "integer",
"format": "int64",
"nullable": true,
"minimum": 0
}
},
Expand Down
4 changes: 2 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6148,11 +6148,11 @@
{
"name": "lastReadMessage",
"in": "query",
"description": "ID if the last read message",
"required": true,
"description": "ID if the last read message (Optional only with `chat-read-last` capability)",
"schema": {
"type": "integer",
"format": "int64",
"nullable": true,
"minimum": 0
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2431,9 +2431,9 @@ export type operations = {
/** Set the read marker to a specific message */
"chat-set-read-marker": {
parameters: {
query: {
/** @description ID if the last read message */
lastReadMessage: number;
query?: {
/** @description ID if the last read message (Optional only with `chat-read-last` capability) */
lastReadMessage?: number | null;
};
header: {
/** @description Required to be true for the API request to pass */
Expand Down
6 changes: 3 additions & 3 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2268,9 +2268,9 @@ export type operations = {
/** Set the read marker to a specific message */
"chat-set-read-marker": {
parameters: {
query: {
/** @description ID if the last read message */
lastReadMessage: number;
query?: {
/** @description ID if the last read message (Optional only with `chat-read-last` capability) */
lastReadMessage?: number | null;
};
header: {
/** @description Required to be true for the API request to pass */
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,7 @@ public function userReadsMessageInRoom($user, $message, $identifier, $statusCode
$this->setCurrentUser($user);
$this->sendRequest(
'POST', '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '/read',
new TableNode([['lastReadMessage', self::$textToMessageId[$message]]])
$message === 'NULL' ? null : new TableNode([['lastReadMessage', self::$textToMessageId[$message]]]),
);
$this->assertStatusCode($this->response, $statusCode);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/features/chat-2/unread-messages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ Feature: chat-2/unread-messages
Then user "participant2" is participant of room "group room" (v4)
| unreadMessages |
| 1 |
When user "participant2" reads message "NULL" in room "group room" with 200
Then user "participant2" is participant of room "group room" (v4)
| unreadMessages |
| 0 |



Expand Down
1 change: 1 addition & 0 deletions tests/php/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function setUp(): void {
'delete-messages-unlimited',
'edit-messages',
'silent-send-state',
'chat-read-last',
'message-expiration',
'reactions',
];
Expand Down
Loading