From bd7715c68ab9d22da93edf5421e88135b104c6d9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Jun 2020 15:49:28 +0200 Subject: [PATCH] Delete duplicates of the same push token hash Signed-off-by: Joas Schilling --- lib/Controller/PushController.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Controller/PushController.php b/lib/Controller/PushController.php index eb2c58a16..6a2b97ed1 100644 --- a/lib/Controller/PushController.php +++ b/lib/Controller/PushController.php @@ -189,6 +189,9 @@ protected function savePushToken(IUser $user, IToken $token, string $deviceIdent $result->closeCursor(); if (!$row) { + // In case the auth token is new, delete potentially old entries for the same device (push token) by this user + $this->deletePushTokenByHash($user, $pushTokenHash); + return $this->insertPushToken($user, $token, $deviceIdentifier, $devicePublicKey, $pushTokenHash, $proxyServer, $appType); } @@ -261,4 +264,18 @@ protected function deletePushToken(IUser $user, IToken $token): bool { return $query->execute() !== 0; } + + /** + * @param IUser $user + * @param string $pushTokenHash + * @return bool If the entry was deleted + */ + protected function deletePushTokenByHash(IUser $user, string $pushTokenHash): bool { + $query = $this->db->getQueryBuilder(); + $query->delete('notifications_pushtokens') + ->where($query->expr()->eq('uid', $query->createNamedParameter($user->getUID()))) + ->andWhere($query->expr()->eq('pushtokenhash', $query->createNamedParameter($pushTokenHash))); + + return $query->execute() !== 0; + } }