summary refs log tree commit diff
path: root/synapse/push
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-01-29 16:18:59 +0000
committerMark Haines <mark.haines@matrix.org>2015-01-29 16:18:59 +0000
commit8e571cbed8c1eccea169589362fa977406f594a6 (patch)
tree4723970b6cf46305c1db16145d05acc026fea3e7 /synapse/push
parentMerge branch 'client_v2_filter' into client_v2_sync (diff)
parentMerge branch 'develop' into client_v2_filter (diff)
downloadsynapse-8e571cbed8c1eccea169589362fa977406f594a6.tar.xz
Merge branch 'client_v2_filter' into client_v2_sync
Diffstat (limited to 'synapse/push')
-rw-r--r--synapse/push/__init__.py22
-rw-r--r--synapse/push/httppusher.py8
-rw-r--r--synapse/push/pusherpool.py2
3 files changed, 18 insertions, 14 deletions
diff --git a/synapse/push/__init__.py b/synapse/push/__init__.py
index 10ac890482..472ede5480 100644
--- a/synapse/push/__init__.py
+++ b/synapse/push/__init__.py
@@ -56,6 +56,7 @@ class Pusher(object):
 
         # The last value of last_active_time that we saw
         self.last_last_active_time = 0
+        self.has_unread = True
 
     @defer.inlineCallbacks
     def _actions_for_event(self, ev):
@@ -180,6 +181,7 @@ class Pusher(object):
                 processed = True
             else:
                 rejected = yield self.dispatch_push(single_event, tweaks)
+                self.has_unread = True
                 if isinstance(rejected, list) or isinstance(rejected, tuple):
                     processed = True
                     for pk in rejected:
@@ -187,8 +189,8 @@ class Pusher(object):
                             # for sanity, we only remove the pushkey if it
                             # was the one we actually sent...
                             logger.warn(
-                                ("Ignoring rejected pushkey %s because we "
-                                "didn't send it"), pk
+                                ("Ignoring rejected pushkey %s because we"
+                                 " didn't send it"), pk
                             )
                         else:
                             logger.info(
@@ -234,8 +236,7 @@ class Pusher(object):
                     # of old notifications.
                     logger.warn("Giving up on a notification to user %s, "
                                 "pushkey %s",
-                                self.user_name, self.pushkey
-                    )
+                                self.user_name, self.pushkey)
                     self.backoff_delay = Pusher.INITIAL_BACKOFF
                     self.last_token = chunk['end']
                     self.store.update_pusher_last_token(
@@ -256,8 +257,7 @@ class Pusher(object):
                                 "Trying again in %dms",
                                 self.user_name,
                                 self.clock.time_msec() - self.failing_since,
-                                self.backoff_delay
-                    )
+                                self.backoff_delay)
                     yield synapse.util.async.sleep(self.backoff_delay / 1000.0)
                     self.backoff_delay *= 2
                     if self.backoff_delay > Pusher.MAX_BACKOFF:
@@ -290,9 +290,11 @@ class Pusher(object):
         if 'last_active' in state.state:
             last_active = state.state['last_active']
             if last_active > self.last_last_active_time:
-                logger.info("Resetting badge count for %s", self.user_name)
-                self.reset_badge_count()
                 self.last_last_active_time = last_active
+                if self.has_unread:
+                    logger.info("Resetting badge count for %s", self.user_name)
+                    self.reset_badge_count()
+                    self.has_unread = False
 
 
 def _value_for_dotted_key(dotted_key, event):
@@ -305,6 +307,7 @@ def _value_for_dotted_key(dotted_key, event):
         parts = parts[1:]
     return val
 
+
 def _tweaks_for_actions(actions):
     tweaks = {}
     for a in actions:
@@ -314,6 +317,7 @@ def _tweaks_for_actions(actions):
             tweaks['sound'] = a['set_sound']
     return tweaks
 
+
 class PusherConfigException(Exception):
     def __init__(self, msg):
-        super(PusherConfigException, self).__init__(msg)
\ No newline at end of file
+        super(PusherConfigException, self).__init__(msg)
diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py
index e12b946727..ab128e31e5 100644
--- a/synapse/push/httppusher.py
+++ b/synapse/push/httppusher.py
@@ -71,11 +71,11 @@ class HttpPusher(Pusher):
                 # we may have to fetch this over federation and we
                 # can't trust it anyway: is it worth it?
                 #'from_display_name': 'Steve Stevington'
-                'counts': { #-- we don't mark messages as read yet so
-                # we have no way of knowing
+                'counts': {  # -- we don't mark messages as read yet so
+                             # we have no way of knowing
                     # Just set the badge to 1 until we have read receipts
                     'unread': 1,
-                #    'missed_calls': 2
+                    # 'missed_calls': 2
                 },
                 'devices': [
                     {
@@ -142,4 +142,4 @@ class HttpPusher(Pusher):
         rejected = []
         if 'rejected' in resp:
             rejected = resp['rejected']
-        defer.returnValue(rejected)
\ No newline at end of file
+        defer.returnValue(rejected)
diff --git a/synapse/push/pusherpool.py b/synapse/push/pusherpool.py
index 856defedac..4892c21e7b 100644
--- a/synapse/push/pusherpool.py
+++ b/synapse/push/pusherpool.py
@@ -149,4 +149,4 @@ class PusherPool:
             logger.info("Stopping pusher %s", fullid)
             self.pushers[fullid].stop()
             del self.pushers[fullid]
-        yield self.store.delete_pusher_by_app_id_pushkey(app_id, pushkey)
\ No newline at end of file
+        yield self.store.delete_pusher_by_app_id_pushkey(app_id, pushkey)