Browse Source

fix(threads): Fix list of message ids for preloading threads

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/15860/head
Joas Schilling 2 months ago
parent
commit
a9ad76e55b
No known key found for this signature in database GPG Key ID: F72FA5B49FFA96B0
  1. 20
      lib/Controller/RoomController.php
  2. 3
      lib/Service/ThreadService.php

20
lib/Controller/RoomController.php

@ -278,7 +278,7 @@ class RoomController extends AEnvironmentAwareOCSController {
$this->commonReadMessages = $this->participantService->getLastCommonReadChatMessageForMultipleRooms($roomIds);
}
$statuses = [];
$statuses = $threads = [];
if ($includeStatus
&& $this->appManager->isEnabledForUser('user_status')) {
$userIds = array_filter(array_map(function (Room $room) {
@ -297,16 +297,24 @@ class RoomController extends AEnvironmentAwareOCSController {
}
if ($includeLastMessage) {
$lastMessages = array_filter(array_map(static fn (Room $room) => $room->getLastMessage()?->getVerb() === 'object_shared' ? $room->getLastMessage() : null, $rooms));
$potentialThreads = array_map(static fn (IComment $lastMessage) => (int)$lastMessage->getTopmostParentId(), $lastMessages);
$this->sharePreloader->preloadShares($lastMessages);
$threads = $this->threadService->preloadThreads($potentialThreads);
$sharesInLastMessages = array_filter(array_map(static fn (Room $room): ?IComment => $room->getLastMessage()?->getVerb() === 'object_shared' ? $room->getLastMessage() : null, $rooms));
$this->sharePreloader->preloadShares($sharesInLastMessages);
$lastLocalMessages = array_filter(array_map(static fn (Room $room): ?IComment => !$room->isFederatedConversation() ? $room->getLastMessage() : null, $rooms));
$potentialThreads = array_map(static fn (IComment $lastMessage): int => (int)$lastMessage->getTopmostParentId() ?: (int)$lastMessage->getId(), $lastLocalMessages);
$threads = $this->threadService->preloadThreadsForConversationList($potentialThreads);
}
$return = [];
foreach ($rooms as $room) {
try {
$return[] = $this->formatRoom($room, $this->participantService->getParticipant($room, $this->userId), $statuses, skipLastMessage: !$includeLastMessage, thread: $threads[$room->getId()] ?? null);
$return[] = $this->formatRoom(
$room,
$this->participantService->getParticipant($room, $this->userId),
$statuses,
skipLastMessage: !$includeLastMessage,
thread: $threads[$room->getId()] ?? null
);
} catch (ParticipantNotFoundException $e) {
// for example in case the room was deleted concurrently,
// the user is not a participant anymore

3
lib/Service/ThreadService.php

@ -69,10 +69,11 @@ class ThreadService {
}
/**
* @internal Warning: does not check room memberships
* @param list<non-negative-int> $threadIds
* @return array<int, Thread> Map with room id as key
*/
public function preloadThreads(array $threadIds): array {
public function preloadThreadsForConversationList(array $threadIds): array {
$threads = $this->threadMapper->getForIds($threadIds);
$result = [];
foreach ($threads as $thread) {

Loading…
Cancel
Save