Skip to content

Commit

Permalink
feat(federation): Allow to mark a conversation as unread again
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 28, 2024
1 parent 553bb47 commit 8b63fb0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob
+ `404 Not Found` When the room could not be found for the participant,
or the participant is a guest.

- Data in case of `200 OK`: See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations)

- Header:

| field | type | Description |
Expand Down
13 changes: 10 additions & 3 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,13 +1082,20 @@ public function setReadMarker(int $lastReadMessage): DataResponse {
/**
* Mark a chat as unread
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{X-Chat-Last-Common-Read?: numeric-string}>
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{X-Chat-Last-Common-Read?: numeric-string}>
*
* 200: Read marker set successfully
*/
#[NoAdminRequired]
#[RequireParticipant]
#[FederationSupported]
#[PublicPage]
#[RequireAuthenticatedParticipant]
public function markUnread(): 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->markUnread($this->room, $this->participant, $this->getResponseFormat());
}

$message = $this->room->getLastMessage();
$unreadId = 0;

Expand Down
40 changes: 40 additions & 0 deletions lib/Federation/Proxy/TalkV1/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,46 @@ public function setReadMarker(Room $room, Participant $participant, string $resp
), Http::STATUS_OK, $headers);
}

/**
* @see \OCA\Talk\Controller\ChatController::markUnread()
*
* @param 'json'|'xml' $responseFormat
* @return DataResponse<Http::STATUS_OK, TalkRoom, array{X-Chat-Last-Common-Read?: numeric-string}>
* @throws CannotReachRemoteException
*
* 200: List of mention suggestions returned
*/
public function markUnread(Room $room, Participant $participant, string $responseFormat): DataResponse {
$proxy = $this->proxy->delete(
$participant->getAttendee()->getInvitedCloudId(),
$participant->getAttendee()->getAccessToken(),
$room->getRemoteServer() . '/ocs/v2.php/apps/spreed/api/v1/chat/' . $room->getRemoteToken() . '/read',
);

/** @var TalkRoom $data */
$data = $this->proxy->getOCSData($proxy);

$this->participantService->updateUnreadInfoForProxyParticipant(
$participant,
$data['unreadMessages'],
$data['unreadMention'],
$data['unreadMentionDirect'],
);

$headers = $lastCommonRead = [];
if ($proxy->getHeader('X-Chat-Last-Common-Read')) {
$lastCommonRead[$room->getId()] = (int) $proxy->getHeader('X-Chat-Last-Common-Read');
$headers['X-Chat-Last-Common-Read'] = (string) $lastCommonRead[$room->getId()];
}

return new DataResponse($this->roomFormatter->formatRoom(
$responseFormat,
$lastCommonRead,
$room,
$participant,
), Http::STATUS_OK, $headers);
}

/**
* @see \OCA\Talk\Controller\ChatController::mentions()
*
Expand Down
5 changes: 4 additions & 1 deletion openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6297,6 +6297,7 @@
"chat"
],
"security": [
{},
{
"bearer_auth": []
},
Expand Down Expand Up @@ -6365,7 +6366,9 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
"data": {
"$ref": "#/components/schemas/Room"
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6179,6 +6179,7 @@
"chat"
],
"security": [
{},
{
"bearer_auth": []
},
Expand Down Expand Up @@ -6247,7 +6248,9 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
"data": {
"$ref": "#/components/schemas/Room"
}
}
}
}
Expand Down

0 comments on commit 8b63fb0

Please sign in to comment.