Skip to content

Commit

Permalink
fix(federation): Don't double convert the actor info in the last message
Browse files Browse the repository at this point in the history
The PCM cache is already converted, so converting again on rendering,
would create a conflict if there is a user1 from host and proxy in the room.

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Mar 27, 2024
1 parent 48634fe commit 50e55d2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Service/RoomFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public function formatRoomV4(
$room->getRemoteToken(),
$room->getLastMessageId(),
);
$roomData['lastMessage'] = $this->userConverter->convertAttendee($room, $cachedMessage->jsonSerialize(), 'actorType', 'actorId', 'actorDisplayName');
$roomData['lastMessage'] = $cachedMessage->jsonSerialize();
} catch (DoesNotExistException) {
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@ private function assertRooms($rooms, TableNode $formData, bool $shouldOrder = fa
if (isset($expectedRoom['lastMessage'])) {
$data['lastMessage'] = $room['lastMessage'] ? $room['lastMessage']['message'] : '';
}
if (isset($expectedRoom['lastMessageActorType'])) {
$data['lastMessageActorType'] = $room['lastMessage'] ? $room['lastMessage']['actorType'] : '';
}
if (isset($expectedRoom['lastMessageActorId'])) {
$data['lastMessageActorId'] = $room['lastMessage'] ? $room['lastMessage']['actorId'] : '';
$data['lastMessageActorId'] = str_replace(rtrim($this->baseUrl, '/'), '{$BASE_URL}', $data['lastMessageActorId']);
$data['lastMessageActorId'] = str_replace(rtrim($this->baseRemoteUrl, '/'), '{$REMOTE_URL}', $data['lastMessageActorId']);
}
if (isset($expectedRoom['lastReadMessage'])) {
$data['lastReadMessage'] = self::$messageIdToText[(int) $room['lastReadMessage']] ?? (!$room['lastReadMessage'] ? 'ZERO': 'UNKNOWN_MESSAGE');
}
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/features/federation/chat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ Feature: federation/chat
| id | type | lastMessage |
| room | 2 | Message deleted by author |

Scenario: Last message actor when the same user ID is present
Given the following "spreed" app config is set
| federation_enabled | yes |
Given user "participant1" creates room "room" (v4)
| roomType | 2 |
| roomName | room |
And user "participant1" adds federated_user "participant1" to room "room" with 200 (v4)
And user "participant1" has the following invitations (v1)
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
And user "participant1" accepts invite to room "room" of server "LOCAL" with 200 (v1)
| id | name | type | remoteServer | remoteToken |
| room | room | 2 | LOCAL | room |
Then user "participant1" is participant of the following rooms (v4)
| id | type | lastMessage |
| room | 2 | {actor} invited you |
| room | 2 | {federated_user} accepted the invitation |
And user "participant1" sends message "Message 1" to room "room" with 201
Then user "participant1" is participant of the following rooms (v4)
| id | type | lastMessage | lastMessageActorType | lastMessageActorId |
| room | 2 | Message 1 | users | participant1 |
| room | 2 | Message 1 | federated_users | participant1@{$BASE_URL} |
When user "participant1" sends reply "Message 1-1" on message "Message 1" to room "LOCAL::room" with 201
Then user "participant1" is participant of the following rooms (v4)
| id | type | lastMessage | lastMessageActorType | lastMessageActorId |
| room | 2 | Message 1-1 | federated_users | participant1@{$REMOTE_URL} |
| room | 2 | Message 1-1 | users | participant1 |

Scenario: Read marker checking
Given the following "spreed" app config is set
| federation_enabled | yes |
Expand Down

0 comments on commit 50e55d2

Please sign in to comment.