Commit f66dc6a912c163e3ce1b526a867ef9e5ad2e9e2b

Authored by Rohan Rangray
1 parent 137e48f922
Exists in master

If the client's registration id is invalid, remove it

Showing 1 changed file with 8 additions and 5 deletions Side-by-side Diff

flashcards/models.py View file @ f66dc6a
... ... @@ -2,7 +2,7 @@
2 2 from math import exp
3 3 from datetime import timedelta
4 4  
5   -from gcm import GCM
  5 +from gcm import GCM, gcm
6 6 from django.contrib.auth.models import AbstractUser, UserManager
7 7 from django.contrib.auth.tokens import default_token_generator
8 8 from django.core.cache import cache
... ... @@ -100,10 +100,13 @@
100 100  
101 101 def notify(self):
102 102 gcm = GCM(GCM_API_KEY)
103   - gcm.plaintext_request(
104   - registration_id=self.registration_id,
105   - data={'poop': 'data'}
106   - )
  103 + try:
  104 + gcm.plaintext_request(
  105 + registration_id=self.registration_id,
  106 + data={'poop': 'data'}
  107 + )
  108 + except (gcm.GCMInvalidRegistrationException, gcm.GCMMissingRegistrationException):
  109 + self.registration_id = None
107 110 self.last_notified = now()
108 111 self.save()
109 112