mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
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.
This commit is contained in:
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user