Skip to content

Commit

Permalink
Merge pull request #11846 from nextcloud/bugfix/noid/toggle-privacy-c…
Browse files Browse the repository at this point in the history
…onfig

fix(federation): Disable read and typing indicators for federated users
  • Loading branch information
nickvergessen authored Mar 18, 2024
2 parents 49e33e6 + 8649489 commit 3447f43
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 99 deletions.
4 changes: 2 additions & 2 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http::STATUS_OK|Http::STATUS_NOT_MODIFIED, TalkChatMessageWithParent[], array{X-Chat-Last-Common-Read?: numeric-string, X-Chat-Last-Given?: numeric-string}>
* @return DataResponse<Http::STATUS_OK, TalkChatMessageWithParent[], array{'X-Chat-Last-Common-Read'?: numeric-string, X-Chat-Last-Given?: numeric-string}>|DataResponse<Http::STATUS_NOT_MODIFIED, array<empty>, array<empty>>
*
* 200: Messages returned
* 304: No messages
Expand Down Expand Up @@ -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<Http::STATUS_OK|Http::STATUS_NOT_MODIFIED, TalkChatMessageWithParent[], array{X-Chat-Last-Common-Read?: numeric-string, X-Chat-Last-Given?: numeric-string}>
* @return DataResponse<Http::STATUS_OK, TalkChatMessageWithParent[], array{'X-Chat-Last-Common-Read'?: numeric-string, X-Chat-Last-Given?: numeric-string}>|DataResponse<Http::STATUS_NOT_MODIFIED, array<empty>, array<empty>>
*
* 200: Message context returned
* 304: No messages
Expand Down
9 changes: 9 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<empty> $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'];
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Federation/Proxy/TalkV1/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public function sendMessage(Room $room, Participant $participant, string $messag
return new DataResponse(
$data,
Http::STATUS_CREATED,
$headers
$headers,
);
}

/**
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_MODIFIED, TalkChatMessageWithParent[], array{X-Chat-Last-Common-Read?: numeric-string, X-Chat-Last-Given?: numeric-string}>
* @return DataResponse<Http::STATUS_OK, TalkChatMessageWithParent[], array{'X-Chat-Last-Common-Read'?: numeric-string, X-Chat-Last-Given?: numeric-string}>|DataResponse<Http::STATUS_NOT_MODIFIED, array<empty>, array<empty>>
* @throws CannotReachRemoteException
*
* 200: Messages returned
Expand Down Expand Up @@ -214,7 +214,7 @@ public function receiveMessages(
}

/**
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_MODIFIED, TalkChatMessageWithParent[], array{X-Chat-Last-Common-Read?: numeric-string, X-Chat-Last-Given?: numeric-string}>
* @return DataResponse<Http::STATUS_OK, TalkChatMessageWithParent[], array{'X-Chat-Last-Common-Read'?: numeric-string, X-Chat-Last-Given?: numeric-string}>|DataResponse<Http::STATUS_NOT_MODIFIED, array<empty>, array<empty>>
* @throws CannotReachRemoteException
*
* 200: Message context returned
Expand Down Expand Up @@ -307,7 +307,7 @@ public function editMessage(Room $room, Participant $participant, int $messageId
return new DataResponse(
$data,
$statusCode,
$headers
$headers,
);
}

Expand Down Expand Up @@ -358,7 +358,7 @@ public function deleteMessage(Room $room, Participant $participant, int $message
return new DataResponse(
$data,
$statusCode,
$headers
$headers,
);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
38 changes: 2 additions & 36 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -4855,12 +4843,7 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChatMessageWithParent"
}
}
"data": {}
}
}
}
Expand Down Expand Up @@ -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": {
Expand All @@ -5971,12 +5942,7 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChatMessageWithParent"
}
}
"data": {}
}
}
}
Expand Down
38 changes: 2 additions & 36 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -4742,12 +4730,7 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChatMessageWithParent"
}
}
"data": {}
}
}
}
Expand Down Expand Up @@ -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": {
Expand All @@ -5858,12 +5829,7 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChatMessageWithParent"
}
}
"data": {}
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down Expand Up @@ -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;
};
};
};
Expand Down
12 changes: 2 additions & 10 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down Expand Up @@ -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;
};
};
};
Expand Down

0 comments on commit 3447f43

Please sign in to comment.