From a9e2ceb4e9b1146b28db3469caaccdfaebc6d1b6 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 15 Sep 2016 06:24:28 -0700 Subject: [PATCH] push notifications: Fix very minor quirk when adding tokens. When we push a device token, we want to clean out any other user's tokens on the device, but not the current user's. We were wiping away our own token, if it existed, before creating it again. This was probably never a user-facing problem; it just made for dead code and a little unnecessary DB churn. By excluding the current user from the delete() call, we exercise the update path in our tests now, so we have 100% coverage. --- zerver/views/push_notifications.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zerver/views/push_notifications.py b/zerver/views/push_notifications.py index fd121dc6fd..29ccc94a3c 100644 --- a/zerver/views/push_notifications.py +++ b/zerver/views/push_notifications.py @@ -19,13 +19,14 @@ def add_push_device_token(request, user_profile, token_str, kind, ios_app_id=Non # If another user was previously logged in on the same device and didn't # properly log out, the token will still be registered to the wrong account - PushDeviceToken.objects.filter(token=token_str).delete() + PushDeviceToken.objects.filter(token=token_str).exclude(user=user_profile).delete() # Overwrite with the latest value token, created = PushDeviceToken.objects.get_or_create(user=user_profile, token=token_str, - kind=kind, - ios_app_id=ios_app_id) + defaults=dict( + kind=kind, + ios_app_id=ios_app_id)) if not created: token.last_updated = now() token.save(update_fields=['last_updated'])