diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 8fa599511d0..77f985aeb0b 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -182,7 +182,8 @@ protected function parseCommentToResponse(IComment $comment, ?Message $parentMes } try { - $thread = $this->threadService->findByThreadId($this->room->getId(), (int)$comment->getTopmostParentId()); + $threadId = (int)$comment->getTopmostParentId() ?: (int)$comment->getId(); + $thread = $this->threadService->findByThreadId($this->room->getId(), $threadId); } catch (DoesNotExistException) { $thread = null; } @@ -682,7 +683,7 @@ protected function prepareCommentsAsDataResponse(array $comments, int $lastCommo } $this->sharePreloader->preloadShares($comments); - $potentialThreadIds = array_map(static fn (IComment $comment) => (int)$comment->getTopmostParentId(), $comments); + $potentialThreadIds = array_map(static fn (IComment $comment) => (int)$comment->getTopmostParentId() ?: (int)$comment->getId(), $comments); $threads = $this->threadService->findByThreadIds($this->room->getId(), $potentialThreadIds); $i = 0; @@ -984,7 +985,8 @@ public function deleteMessage(int $messageId): DataResponse { $this->messageParser->parseMessage($message); try { - $thread = $this->threadService->findByThreadId($this->room->getId(), (int)$comment->getTopmostParentId()); + $threadId = (int)$comment->getTopmostParentId() ?: (int)$comment->getId(); + $thread = $this->threadService->findByThreadId($this->room->getId(), $threadId); } catch (DoesNotExistException) { $thread = null; } @@ -1107,7 +1109,8 @@ public function editMessage(int $messageId, string $message): DataResponse { $this->messageParser->parseMessage($parseMessage); try { - $thread = $this->threadService->findByThreadId($this->room->getId(), (int)$comment->getTopmostParentId()); + $threadId = (int)$comment->getTopmostParentId() ?: (int)$comment->getId(); + $thread = $this->threadService->findByThreadId($this->room->getId(), $threadId); } catch (DoesNotExistException) { $thread = null; } @@ -1626,7 +1629,7 @@ public function getObjectsSharedInRoom(string $objectType, int $lastKnownMessage protected function getMessagesForRoom(array $messageIds): array { $comments = $this->chatManager->getMessagesForRoomById($this->room, $messageIds); $this->sharePreloader->preloadShares($comments); - $potentialThreadIds = array_map(static fn (IComment $comment) => (int)$comment->getTopmostParentId(), $comments); + $potentialThreadIds = array_map(static fn (IComment $comment) => (int)$comment->getTopmostParentId() ?: (int)$comment->getId(), $comments); $threads = $this->threadService->findByThreadIds($this->room->getId(), $potentialThreadIds); $messages = []; @@ -1646,7 +1649,7 @@ protected function getMessagesForRoom(array $messageIds): array { continue; } - $threadId = (int)$comment->getTopmostParentId(); + $threadId = (int)$comment->getTopmostParentId() ?: (int)$comment->getId(); $messages[$comment->getId()] = $message->toArray($this->getResponseFormat(), $threads[$threadId] ?? null); }