Skip to content

Commit

Permalink
Merge pull request #13376 from nextcloud/backport/13290/stable30
Browse files Browse the repository at this point in the history
[stable30] fix(changelog): Don't check the user changelog twice
  • Loading branch information
nickvergessen committed Sep 23, 2024
2 parents 03e90bf + 5d4159d commit e74714e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 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());
}
}
21 changes: 11 additions & 10 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 Expand Up @@ -129,11 +130,11 @@ public function getChangelogs(): array {
$this->l->t('## New in Talk %s', ['19']) . "\n"
. $this->l->t('- Messages can now be edited by logged-in authors and moderators for 6 hours') . "\n"
. $this->l->t('- Unsent message drafts are now saved in your browser') . "\n"
. $this->l->t('- *Preview:* Text chatting can now be done in a federated way with other Talk servers'),
. $this->l->t('- Text chatting can now be done in a federated way with other Talk servers'),
$this->l->t('## New in Talk %s', ['20']) . "\n"
. $this->l->t('- Moderators can now ban accounts and guests to prevent them from rejoining a conversation') . "\n"
. $this->l->t('- Upcoming calls from linked calendar events and out-of-office replacements are now shown in conversations') . "\n"
. $this->l->t('- *Preview:* Calls can now be done in a federated way with other Talk servers (requires the High-performance backend)'),
. $this->l->t('- Calls can now be done in a federated way with other Talk servers (requires the High-performance backend)'),
];
}
}

0 comments on commit e74714e

Please sign in to comment.