Fetching notifications works again, fixes #31
authorMarek Marecki <marekjm@ozro.pw>
Sun, 23 Apr 2017 14:27:15 +0000 (16:27 +0200)
committerMarek Marecki <marekjm@ozro.pw>
Sun, 23 Apr 2017 14:27:15 +0000 (16:27 +0200)
diaspy/models.py
diaspy/notifications.py

index 8371194c438d7578e4915ba775c943ede7cdf311..c58f38bc52660c5c9e513616dfcbfb29f4334684 100644 (file)
@@ -148,7 +148,7 @@ class Notification():
 
     def __init__(self, connection, data):
         self._connection = connection
-        self.type = list(data.keys())[0]
+        self.type = data['type']
         self._data = data[self.type]
         self.id = self._data['id']
         self.unread = self._data['unread']
index bfcfadac21784a69002bfa12cf0aae80896dab18..8393c7585a8e8362898d8c5c11d0da5ae3fb2bc2 100644 (file)
@@ -15,6 +15,7 @@ class Notifications():
     """
     def __init__(self, connection):
         self._connection = connection
+        self._data = {}
         self._notifications = self.get()
 
     def __iter__(self):
@@ -47,4 +48,6 @@ class Notifications():
             raise Exception('status code: {0}: cannot retreive notifications'.format(request.status_code))
 
         notifications = request.json()
-        return [Notification(self._connection, n) for n in notifications]
+        self._data['unread_count'] = notifications['unread_count']
+        self._data['unread_count_by_type'] = notifications['unread_count_by_type']
+        return [Notification(self._connection, n) for n in notifications.get('notification_list', [])]