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:
Tim Abbott
2018-03-23 10:23:23 -07:00
parent 5e4b445649
commit 62c0d27d1e

View File

@@ -214,9 +214,9 @@ def send_android_push_notification(devices: List[DeviceToken], data: Dict[str, A
if error in ['NotRegistered', 'InvalidRegistration']: if error in ['NotRegistered', 'InvalidRegistration']:
for reg_id in reg_ids: for reg_id in reg_ids:
logging.info("GCM: Removing %s" % (reg_id,)) logging.info("GCM: Removing %s" % (reg_id,))
# We remove all entries for this token (There
device = DeviceTokenClass.objects.get(token=reg_id, kind=DeviceTokenClass.GCM) # could be multiple for different Zulip servers).
device.delete() DeviceTokenClass.objects.filter(token=reg_id, kind=DeviceTokenClass.GCM).delete()
else: else:
for reg_id in reg_ids: for reg_id in reg_ids:
logging.warning("GCM: Delivery to %s failed: %s" % (reg_id, error)) logging.warning("GCM: Delivery to %s failed: %s" % (reg_id, error))