Skip to content

Commit

Permalink
fix(federation): Store last message id from the proxied message
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 28, 2024
1 parent 93f18f5 commit 4303d47
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/Federation/CloudFederationProviderTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 4303d47

Please sign in to comment.