From 2ee2183331b0207b3989087494e5857d97dbd90d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Mar 2024 16:20:15 +0100 Subject: [PATCH 1/2] fix(federation): Disable read and typing indicators for federated users Signed-off-by: Joas Schilling --- lib/Controller/ChatController.php | 4 ++-- lib/Controller/RoomController.php | 9 +++++++++ .../Proxy/TalkV1/Controller/ChatController.php | 10 +++++----- lib/Service/ParticipantService.php | 3 +++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 4edf7791fce..13e40592b15 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -412,7 +412,7 @@ protected function preloadShares(array $comments): void { * @param 0|1 $includeLastKnown Include the $lastKnownMessageId in the messages when 1 (default 0) * @param 0|1 $noStatusUpdate When the user status should not be automatically set to online set to 1 (default 0) * @param 0|1 $markNotificationsAsRead Set to 0 when notifications should not be marked as read (default 1) - * @return DataResponse + * @return DataResponse|DataResponse, array> * * 200: Messages returned * 304: No messages @@ -642,7 +642,7 @@ protected function prepareCommentsAsDataResponse(array $comments, int $lastCommo * @psalm-param non-negative-int $messageId * @param 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100 $limit Number of chat messages to receive in both directions (50 by default, 100 at most, might return 201 messages) * @psalm-param int<1, 100> $limit - * @return DataResponse + * @return DataResponse|DataResponse, array> * * 200: Message context returned * 304: No messages diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index c555a5e961d..c82d09ebbc7 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -2253,7 +2253,16 @@ public function getCapabilities(): DataResponse { $proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\RoomController::class); $response = $proxy->getCapabilities($this->room, $this->participant); + /** @var TalkCapabilities|array $data */ $data = $response->getData(); + + if (isset($data['config']['chat']['read-privacy'])) { + $data['config']['chat']['read-privacy'] = Participant::PRIVACY_PRIVATE; + } + if (isset($data['config']['chat']['typing-privacy'])) { + $data['config']['chat']['typing-privacy'] = Participant::PRIVACY_PRIVATE; + } + if ($response->getHeaders()['X-Nextcloud-Talk-Hash']) { $headers['X-Nextcloud-Talk-Proxy-Hash'] = $response->getHeaders()['X-Nextcloud-Talk-Hash']; } diff --git a/lib/Federation/Proxy/TalkV1/Controller/ChatController.php b/lib/Federation/Proxy/TalkV1/Controller/ChatController.php index a601166d14b..781a5b6605f 100644 --- a/lib/Federation/Proxy/TalkV1/Controller/ChatController.php +++ b/lib/Federation/Proxy/TalkV1/Controller/ChatController.php @@ -112,12 +112,12 @@ public function sendMessage(Room $room, Participant $participant, string $messag return new DataResponse( $data, Http::STATUS_CREATED, - $headers + $headers, ); } /** - * @return DataResponse + * @return DataResponse|DataResponse, array> * @throws CannotReachRemoteException * * 200: Messages returned @@ -214,7 +214,7 @@ public function receiveMessages( } /** - * @return DataResponse + * @return DataResponse|DataResponse, array> * @throws CannotReachRemoteException * * 200: Message context returned @@ -307,7 +307,7 @@ public function editMessage(Room $room, Participant $participant, int $messageId return new DataResponse( $data, $statusCode, - $headers + $headers, ); } @@ -358,7 +358,7 @@ public function deleteMessage(Room $room, Participant $participant, int $message return new DataResponse( $data, $statusCode, - $headers + $headers, ); } diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index f8c0dae7cc6..31c31a6644f 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -483,6 +483,9 @@ public function addUsers(Room $room, array $participants, ?IUser $addedBy = null FederationManager::TOKEN_LENGTH, ISecureRandom::CHAR_HUMAN_READABLE ); + + // Disable read marker for federated users + $readPrivacy = Participant::PRIVACY_PRIVATE; } $attendee = new Attendee(); From 86494893aeec908c42298816f83819b53f4516df Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Mar 2024 17:22:52 +0100 Subject: [PATCH 2/2] fix(openapi): Update OpenAPI specs Signed-off-by: Joas Schilling --- openapi-full.json | 38 ++----------------------------- openapi.json | 38 ++----------------------------- src/types/openapi/openapi-full.ts | 12 ++-------- src/types/openapi/openapi.ts | 12 ++-------- 4 files changed, 8 insertions(+), 92 deletions(-) diff --git a/openapi-full.json b/openapi-full.json index d65693ed2b3..7c4ff1ff372 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -4825,18 +4825,6 @@ }, "304": { "description": "No messages", - "headers": { - "X-Chat-Last-Common-Read": { - "schema": { - "type": "string" - } - }, - "X-Chat-Last-Given": { - "schema": { - "type": "string" - } - } - }, "content": { "application/json": { "schema": { @@ -4855,12 +4843,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ChatMessageWithParent" - } - } + "data": {} } } } @@ -5941,18 +5924,6 @@ }, "304": { "description": "No messages", - "headers": { - "X-Chat-Last-Common-Read": { - "schema": { - "type": "string" - } - }, - "X-Chat-Last-Given": { - "schema": { - "type": "string" - } - } - }, "content": { "application/json": { "schema": { @@ -5971,12 +5942,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ChatMessageWithParent" - } - } + "data": {} } } } diff --git a/openapi.json b/openapi.json index f1cc7f89f87..dafaa2c7c26 100644 --- a/openapi.json +++ b/openapi.json @@ -4712,18 +4712,6 @@ }, "304": { "description": "No messages", - "headers": { - "X-Chat-Last-Common-Read": { - "schema": { - "type": "string" - } - }, - "X-Chat-Last-Given": { - "schema": { - "type": "string" - } - } - }, "content": { "application/json": { "schema": { @@ -4742,12 +4730,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ChatMessageWithParent" - } - } + "data": {} } } } @@ -5828,18 +5811,6 @@ }, "304": { "description": "No messages", - "headers": { - "X-Chat-Last-Common-Read": { - "schema": { - "type": "string" - } - }, - "X-Chat-Last-Given": { - "schema": { - "type": "string" - } - } - }, "content": { "application/json": { "schema": { @@ -5858,12 +5829,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ChatMessageWithParent" - } - } + "data": {} } } } diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index 3a7fbf37ca6..90ec9bcd5f4 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -1941,15 +1941,11 @@ export type operations = { }; /** @description No messages */ 304: { - headers: { - "X-Chat-Last-Common-Read"?: string; - "X-Chat-Last-Given"?: string; - }; content: { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: components["schemas"]["ChatMessageWithParent"][]; + data: unknown; }; }; }; @@ -2329,15 +2325,11 @@ export type operations = { }; /** @description No messages */ 304: { - headers: { - "X-Chat-Last-Common-Read"?: string; - "X-Chat-Last-Given"?: string; - }; content: { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: components["schemas"]["ChatMessageWithParent"][]; + data: unknown; }; }; }; diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 846a56ce411..52251109bfe 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -1772,15 +1772,11 @@ export type operations = { }; /** @description No messages */ 304: { - headers: { - "X-Chat-Last-Common-Read"?: string; - "X-Chat-Last-Given"?: string; - }; content: { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: components["schemas"]["ChatMessageWithParent"][]; + data: unknown; }; }; }; @@ -2160,15 +2156,11 @@ export type operations = { }; /** @description No messages */ 304: { - headers: { - "X-Chat-Last-Common-Read"?: string; - "X-Chat-Last-Given"?: string; - }; content: { "application/json": { ocs: { meta: components["schemas"]["OCSMeta"]; - data: components["schemas"]["ChatMessageWithParent"][]; + data: unknown; }; }; };