From 4303d474aaca2cb2902414cee2e1b268d821b872 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 28 Feb 2024 19:34:09 +0100 Subject: [PATCH] fix(federation): Store last message id from the proxied message Signed-off-by: Joas Schilling --- lib/Federation/CloudFederationProviderTalk.php | 9 ++++++++- lib/Room.php | 10 +++++++++- lib/Service/RoomService.php | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php index 0ff47da250b4..add53f1fda2d 100644 --- a/lib/Federation/CloudFederationProviderTalk.php +++ b/lib/Federation/CloudFederationProviderTalk.php @@ -340,12 +340,19 @@ private function messagePosted(int $remoteAttendeeId, array $notification): arra $message->setMessageType($notification['messageData']['messageType']); $message->setSystemMessage($notification['messageData']['systemMessage']); if ($notification['messageData']['expirationDatetime']) { - $message->setExpirationDateTime(new \DateTimeImmutable($notification['messageData']['expirationDatetime'])); + $message->setExpirationDatetime(new \DateTimeImmutable($notification['messageData']['expirationDatetime'])); } $message->setMessage($notification['messageData']['message']); $message->setMessageParameters($notification['messageData']['messageParameter']); + // FIXME catch unique constraint violation $this->proxyCacheMessagesMapper->insert($message); + $lastMessageId = $room->getLastMessageId(); + if ($notification['messageData']['remoteMessageId'] > $lastMessageId) { + $lastMessageId = (int) $notification['messageData']['remoteMessageId']; + } + $this->roomService->setLastMessageInfo($room, $lastMessageId, new \DateTime()); + if ($this->proxyCacheMessages instanceof ICache) { $cacheKey = sha1(json_encode([$notification['remoteServerUrl'], $notification['remoteToken']])); $cacheData = $this->proxyCacheMessages->get($cacheKey); diff --git a/lib/Room.php b/lib/Room.php index 381d0ff54701..d6ef91e98a48 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -342,8 +342,16 @@ public function setLastActivity(\DateTime $now): void { $this->lastActivity = $now; } + public function getLastMessageId(): int { + return $this->lastMessageId; + } + + public function setLastMessageId(int $lastMessageId): void { + $this->lastMessageId = $lastMessageId; + } + public function getLastMessage(): ?IComment { - if ($this->lastMessageId && $this->lastMessage === null) { + if ($this->lastMessageId && $this->lastMessage === null && $this->getRemoteServer() !== '') { $this->lastMessage = $this->manager->loadLastCommentInfo($this->lastMessageId); if ($this->lastMessage === null) { $this->lastMessageId = 0; diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 1173d359aa07..d606282dd88a 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -874,6 +874,18 @@ public function setLastMessage(Room $room, IComment $message): void { $room->setLastActivity($message->getCreationDateTime()); } + public function setLastMessageInfo(Room $room, int $messageId, \DateTime $dateTime): void { + $update = $this->db->getQueryBuilder(); + $update->update('talk_rooms') + ->set('last_message', $update->createNamedParameter($messageId)) + ->set('last_activity', $update->createNamedParameter($dateTime, 'datetime')) + ->where($update->expr()->eq('id', $update->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT))); + $update->executeStatement(); + + $room->setLastMessageId($messageId); + $room->setLastActivity($dateTime); + } + public function setLastActivity(Room $room, \DateTime $now): void { $update = $this->db->getQueryBuilder(); $update->update('talk_rooms')