mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
feat(conversations): Allow to not request the last message when getting rooms
This is useful e.g. when only showing a compact list Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
b21659365b
commit
613f25db88
2 changed files with 22 additions and 10 deletions
|
|
@ -196,13 +196,14 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
* @param 0|1 $noStatusUpdate When the user status should not be automatically set to online set to 1 (default 0)
|
||||
* @param bool $includeStatus Include the user status
|
||||
* @param int $modifiedSince Filter rooms modified after a timestamp
|
||||
* @param bool $includeLastMessage Include the last message, clients should opt-out when only rendering a compact list
|
||||
* @psalm-param non-negative-int $modifiedSince
|
||||
* @return DataResponse<Http::STATUS_OK, list<TalkRoom>, array{X-Nextcloud-Talk-Hash: string, X-Nextcloud-Talk-Modified-Before: numeric-string, X-Nextcloud-Talk-Federation-Invites?: numeric-string}>
|
||||
*
|
||||
* 200: Return list of rooms
|
||||
*/
|
||||
#[NoAdminRequired]
|
||||
public function getRooms(int $noStatusUpdate = 0, bool $includeStatus = false, int $modifiedSince = 0): DataResponse {
|
||||
public function getRooms(int $noStatusUpdate = 0, bool $includeStatus = false, int $modifiedSince = 0, bool $includeLastMessage = true): DataResponse {
|
||||
$nextModifiedSince = $this->timeFactory->getTime();
|
||||
|
||||
$event = new BeforeRoomsFetchEvent($this->userId);
|
||||
|
|
@ -227,7 +228,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
}
|
||||
|
||||
$sessionIds = $this->session->getAllActiveSessions();
|
||||
$rooms = $this->manager->getRoomsForUser($this->userId, $sessionIds, true);
|
||||
$rooms = $this->manager->getRoomsForUser($this->userId, $sessionIds, $includeLastMessage);
|
||||
|
||||
if ($modifiedSince !== 0) {
|
||||
$rooms = array_filter($rooms, function (Room $room) use ($includeStatus, $modifiedSince): bool {
|
||||
|
|
@ -280,7 +281,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
$return = [];
|
||||
foreach ($rooms as $room) {
|
||||
try {
|
||||
$return[] = $this->formatRoom($room, $this->participantService->getParticipant($room, $this->userId), $statuses);
|
||||
$return[] = $this->formatRoom($room, $this->participantService->getParticipant($room, $this->userId), $statuses, skipLastMessage: !$includeLastMessage);
|
||||
} catch (ParticipantNotFoundException $e) {
|
||||
// for example in case the room was deleted concurrently,
|
||||
// the user is not a participant anymore
|
||||
|
|
@ -316,7 +317,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
|
||||
$return = [];
|
||||
foreach ($rooms as $room) {
|
||||
$return[] = $this->formatRoom($room, null);
|
||||
$return[] = $this->formatRoom($room, null, skipLastMessage: true);
|
||||
}
|
||||
|
||||
return new DataResponse($return, Http::STATUS_OK);
|
||||
|
|
@ -350,7 +351,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
$participant = null;
|
||||
}
|
||||
|
||||
$return[] = $this->formatRoom($room, $participant, null, false, true);
|
||||
$return[] = $this->formatRoom($room, $participant, null, false, true, true);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -500,7 +501,14 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
/**
|
||||
* @return TalkRoom
|
||||
*/
|
||||
protected function formatRoom(Room $room, ?Participant $currentParticipant, ?array $statuses = null, bool $isSIPBridgeRequest = false, bool $isListingBreakoutRooms = false, array $remoteRoomData = []): array {
|
||||
protected function formatRoom(
|
||||
Room $room,
|
||||
?Participant $currentParticipant,
|
||||
?array $statuses = null,
|
||||
bool $isSIPBridgeRequest = false,
|
||||
bool $isListingBreakoutRooms = false,
|
||||
bool $skipLastMessage = false,
|
||||
): array {
|
||||
return $this->roomFormatter->formatRoom(
|
||||
$this->getResponseFormat(),
|
||||
$this->commonReadMessages,
|
||||
|
|
@ -509,6 +517,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
$statuses,
|
||||
$isSIPBridgeRequest,
|
||||
$isListingBreakoutRooms,
|
||||
$skipLastMessage,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1895,7 +1904,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
return new DataResponse(null, Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
return new DataResponse($this->formatRoom($this->room, $participant));
|
||||
return new DataResponse($this->formatRoom($this->room, $participant, skipLastMessage: true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1946,7 +1955,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
return new DataResponse(null, Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
return new DataResponse($this->formatRoom($this->room, $participant));
|
||||
return new DataResponse($this->formatRoom($this->room, $participant, skipLastMessage: true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1981,7 +1990,7 @@ class RoomController extends AEnvironmentAwareOCSController {
|
|||
|
||||
$participant = $this->participantService->joinRoomAsNewGuest($this->roomService, $this->room, '', true);
|
||||
|
||||
return new DataResponse($this->formatRoom($this->room, $participant));
|
||||
return new DataResponse($this->formatRoom($this->room, $participant, skipLastMessage: true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ class RoomFormatter {
|
|||
?array $statuses = null,
|
||||
bool $isSIPBridgeRequest = false,
|
||||
bool $isListingBreakoutRooms = false,
|
||||
bool $skipLastMessage = false,
|
||||
): array {
|
||||
return $this->formatRoomV4(
|
||||
$responseFormat,
|
||||
|
|
@ -74,6 +75,7 @@ class RoomFormatter {
|
|||
$statuses,
|
||||
$isSIPBridgeRequest,
|
||||
$isListingBreakoutRooms,
|
||||
$skipLastMessage,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +91,7 @@ class RoomFormatter {
|
|||
?array $statuses,
|
||||
bool $isSIPBridgeRequest,
|
||||
bool $isListingBreakoutRooms,
|
||||
bool $skipLastMessage,
|
||||
): array {
|
||||
$roomData = [
|
||||
'id' => $room->getId(),
|
||||
|
|
@ -386,7 +389,7 @@ class RoomFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
$lastMessage = $room->getLastMessage();
|
||||
$lastMessage = $skipLastMessage ? null : $room->getLastMessage();
|
||||
if (!$room->isFederatedConversation() && $lastMessage instanceof IComment) {
|
||||
$lastMessageData = $this->formatLastMessage(
|
||||
$responseFormat,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue