Skip to content

Commit

Permalink
fix(federation): Disable read and typing indicators for federated users
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 18, 2024
1 parent 49e33e6 commit 2ee2183
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 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

0 comments on commit 2ee2183

Please sign in to comment.