summary refs log tree commit diff
path: root/synapse/push/pusherpool.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-01-28 11:55:49 +0000
committerDavid Baker <dave@matrix.org>2015-01-28 11:55:49 +0000
commit273b12729b99addf4474c9092f44ff300fd8153b (patch)
tree7a47bb891027e8f569618ae26708ac55aee4e396 /synapse/push/pusherpool.py
parentOops, remove debugging (diff)
downloadsynapse-273b12729b99addf4474c9092f44ff300fd8153b.tar.xz
Reset badge count to zero when last active time is bumped
Diffstat (limited to 'synapse/push/pusherpool.py')
-rw-r--r--synapse/push/pusherpool.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/push/pusherpool.py b/synapse/push/pusherpool.py
index 2dfecf178b..65ab4f46e1 100644
--- a/synapse/push/pusherpool.py
+++ b/synapse/push/pusherpool.py
@@ -18,6 +18,7 @@ from twisted.internet import defer
 
 from httppusher import HttpPusher
 from synapse.push import PusherConfigException
+from synapse.api.constants import PresenceState
 
 import logging
 import json
@@ -32,6 +33,22 @@ class PusherPool:
         self.pushers = {}
         self.last_pusher_started = -1
 
+        distributor = self.hs.get_distributor()
+        distributor.observe(
+            "user_presence_changed", self.user_presence_changed
+        )
+
+    @defer.inlineCallbacks
+    def user_presence_changed(self, user, state):
+        user_name = user.to_string()
+
+        # until we have read receipts, pushers use this to reset a user's
+        # badge counters to zero
+        for p in self.pushers.values():
+            if p.user_name == user_name:
+                yield p.presence_changed(state)
+
+
     @defer.inlineCallbacks
     def start(self):
         pushers = yield self.store.get_all_pushers()