Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(changelog): Don't check the user changelog twice #13290

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)'),
];
}
}
Loading