fix(threads): Add thread attendee and sync info when replying

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling
2025-06-30 20:50:39 +02:00
parent a7aa05605e
commit 1bb1abc7aa
3 changed files with 33 additions and 1 deletions

View File

@ -400,9 +400,28 @@ class ChatManager {
$shouldFlush = $this->notificationManager->defer();
try {
$this->commentsManager->save($comment);
$messageId = (int)$comment->getId();
$threadId = (int)$comment->getTopmostParentId();
$thread = null;
if ($threadId) {
try {
$thread = $this->threadService->findByThreadId($threadId);
} catch (DoesNotExistException) {
}
}
if ($participant instanceof Participant) {
$this->participantService->updateLastReadMessage($participant, (int)$comment->getId());
$this->participantService->updateLastReadMessage($participant, $messageId);
if ($thread !== null) {
$this->threadService->addAttendeeToThread(
$participant->getAttendee(),
$thread,
);
$this->threadService->updateLastMessageInfoAfterReply($thread, $messageId);
}
}
// Update last_message

View File

@ -262,6 +262,7 @@ class ChatController extends AEnvironmentAwareOCSController {
} catch (IRateLimitExceededException) {
return new DataResponse(['error' => 'mentions'], Http::STATUS_TOO_MANY_REQUESTS);
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return new DataResponse(['error' => 'message'], Http::STATUS_BAD_REQUEST);
}

View File

@ -108,6 +108,18 @@ class ThreadService {
}
}
public function updateLastMessageInfoAfterReply(Thread $thread, int $lastMessageId): void {
$query = $this->connection->getQueryBuilder();
$query->update('talk_threads')
->set('num_replies', $query->func()->add('num_replies', $query->expr()->literal(1)))
->set('last_message_id', $query->createNamedParameter($lastMessageId))
->where($query->expr()->eq('id', $query->createNamedParameter($thread->getId())));
$query->executeStatement();
$thread->setNumReplies($thread->getNumReplies() + 1);
$thread->setLastMessageId($lastMessageId);
}
public function deleteByRoom(Room $room): void {
$this->threadMapper->deleteByRoomId($room->getId());
$this->threadAttendeeMapper->deleteByRoomId($room->getId());