mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
push_notifications: Handle errors with token reuse.
If an Android token has been used to connect a given device with multiple Zulip servers, and then is expired, we would 500 in trying to remove the Zulip-side registration for it, because the code assumed there was only one such registration. If a token is no longer valid, it's invalid for all servers, so the correct fix is to just remove them all.
This commit is contained in:
@@ -214,9 +214,9 @@ def send_android_push_notification(devices: List[DeviceToken], data: Dict[str, A
|
||||
if error in ['NotRegistered', 'InvalidRegistration']:
|
||||
for reg_id in reg_ids:
|
||||
logging.info("GCM: Removing %s" % (reg_id,))
|
||||
|
||||
device = DeviceTokenClass.objects.get(token=reg_id, kind=DeviceTokenClass.GCM)
|
||||
device.delete()
|
||||
# We remove all entries for this token (There
|
||||
# could be multiple for different Zulip servers).
|
||||
DeviceTokenClass.objects.filter(token=reg_id, kind=DeviceTokenClass.GCM).delete()
|
||||
else:
|
||||
for reg_id in reg_ids:
|
||||
logging.warning("GCM: Delivery to %s failed: %s" % (reg_id, error))
|
||||
|
||||
Reference in New Issue
Block a user