Skip to content

Commit

Permalink
feat(occ): Output token validity even when age is cached
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
  • Loading branch information
SystemKeeper committed Dec 9, 2024
1 parent 1a8a3d9 commit f4146e7
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/Push.php
Original file line number Diff line number Diff line change
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

0 comments on commit f4146e7

Please sign in to comment.