From e48f514498fb5a3fdb4ede40df2e791978b69c3b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 13 Sep 2024 08:58:00 +0200 Subject: [PATCH] fix(changelog): Don't count the user changelog twice Signed-off-by: Joas Schilling --- lib/Chat/Changelog/Listener.php | 4 ---- lib/Chat/Changelog/Manager.php | 17 +++++++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/Chat/Changelog/Listener.php b/lib/Chat/Changelog/Listener.php index 4a40457af32..3956bf1ba86 100644 --- a/lib/Chat/Changelog/Listener.php +++ b/lib/Chat/Changelog/Listener.php @@ -32,10 +32,6 @@ public function handle(Event $event): void { return; } - if (!$this->manager->userHasNewChangelog($event->getUserId())) { - return; - } - $this->manager->updateChangelog($event->getUserId()); } } diff --git a/lib/Chat/Changelog/Manager.php b/lib/Chat/Changelog/Manager.php index 6c3c2a9657c..d6996c7fdee 100644 --- a/lib/Chat/Changelog/Manager.php +++ b/lib/Chat/Changelog/Manager.php @@ -32,23 +32,24 @@ public function getChangelogForUser(string $userId): int { return (int)$this->config->getUserValue($userId, 'spreed', 'changelog', '0'); } - public function userHasNewChangelog(string $userId): bool { - return $this->getChangelogForUser($userId) < count($this->getChangelogs()); - } - public function updateChangelog(string $userId): void { - $room = $this->roomManager->getChangelogRoom($userId); - $logs = $this->getChangelogs(); $hasReceivedLog = $this->getChangelogForUser($userId); + $shouldHaveReceived = count($logs); + + if ($hasReceivedLog === $shouldHaveReceived) { + return; + } try { - $this->config->setUserValue($userId, 'spreed', 'changelog', (string)count($logs), (string)$hasReceivedLog); - } catch (PreConditionNotMetException $e) { + $this->config->setUserValue($userId, 'spreed', 'changelog', (string)$shouldHaveReceived, (string)$hasReceivedLog); + } catch (PreConditionNotMetException) { // Parallel request won the race return; } + $room = $this->roomManager->getChangelogRoom($userId); + foreach ($logs as $key => $changelog) { if ($key < $hasReceivedLog || $changelog === '') { continue;