Skip to content

Commit

Permalink
fix(changelog): Don't count the user changelog twice
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Sep 23, 2024
1 parent 03e90bf commit e48f514
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 0 additions & 4 deletions lib/Chat/Changelog/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public function handle(Event $event): void {
return;
}

if (!$this->manager->userHasNewChangelog($event->getUserId())) {
return;
}

$this->manager->updateChangelog($event->getUserId());
}
}
17 changes: 9 additions & 8 deletions lib/Chat/Changelog/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e48f514

Please sign in to comment.