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

feat(occ): Output token validity even when age is cached #2117

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
40 changes: 21 additions & 19 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function pushToDevice(int $id, INotification $notification, ?OutputInterf
foreach ($devices as $device) {
$device['token'] = (int)$device['token'];
$this->printInfo('');
$this->printInfo('Device token:' . $device['token']);
$this->printInfo('Device token: ' . $device['token']);

if (!$this->validateToken($device['token'], $maxAge)) {
// Token does not exist anymore
Expand Down Expand Up @@ -530,27 +530,29 @@ protected function sendNotificationsToProxies(): void {

protected function validateToken(int $tokenId, int $maxAge): bool {
$age = $this->cache->get('t' . $tokenId);
if ($age !== null) {
return $age > $maxAge;
}

try {
// Check if the token is still valid...
$token = $this->tokenProvider->getTokenById($tokenId);
$this->cache->set('t' . $tokenId, $token->getLastCheck(), 600);
if ($token->getLastCheck() > $maxAge) {
$this->printInfo('Device token is valid');
} else {
$this->printInfo('Device token "last checked" is older than 60 days: ' . $token->getLastCheck());
if ($age === null) {
try {
// Check if the token is still valid...
$token = $this->tokenProvider->getTokenById($tokenId);
$this->cache->set('t' . $tokenId, $token->getLastCheck(), 600);
$age = $token->getLastCheck();
} catch (InvalidTokenException) {
// Token does not exist anymore, should drop the push device entry
$this->printInfo('InvalidTokenException is thrown');
$this->deletePushToken($tokenId);
$this->cache->set('t' . $tokenId, 0, 600);
return false;
}
return $token->getLastCheck() > $maxAge;
} catch (InvalidTokenException) {
// Token does not exist anymore, should drop the push device entry
$this->printInfo('InvalidTokenException is thrown');
$this->deletePushToken($tokenId);
$this->cache->set('t' . $tokenId, 0, 600);
return false;
}

if ($age > $maxAge) {
$this->printInfo('Device token is valid');
return true;
}

$this->printInfo('Device token "last checked" is older than 60 days: ' . $age);
return false;
}

/**
Expand Down
Loading