summary refs log tree commit diff
path: root/synapse/handlers/events.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-01-15 16:17:21 +0000
committerDavid Baker <dave@matrix.org>2015-01-15 16:17:21 +0000
commite3e2fc3255665ac888f3e0c0c6e2be39d5fda5f3 (patch)
treec8c94aa48edb27717b8737ac1af734d19db15a7a /synapse/handlers/events.py
parentHonour the 'rejected' return from push gateways (diff)
downloadsynapse-e3e2fc3255665ac888f3e0c0c6e2be39d5fda5f3.tar.xz
Don't make the pushers' event streams cause people to appear online
Diffstat (limited to 'synapse/handlers/events.py')
-rw-r--r--synapse/handlers/events.py43
1 files changed, 22 insertions, 21 deletions
diff --git a/synapse/handlers/events.py b/synapse/handlers/events.py
index c9ade253dd..54ab27004f 100644
--- a/synapse/handlers/events.py
+++ b/synapse/handlers/events.py
@@ -47,11 +47,11 @@ class EventStreamHandler(BaseHandler):
     @defer.inlineCallbacks
     @log_function
     def get_stream(self, auth_user_id, pagin_config, timeout=0,
-                   as_client_event=True):
+                   as_client_event=True, affect_presence=True):
         auth_user = self.hs.parse_userid(auth_user_id)
 
         try:
-            if auth_user not in self._streams_per_user:
+            if affect_presence and auth_user not in self._streams_per_user:
                 self._streams_per_user[auth_user] = 0
                 if auth_user in self._stop_timer_per_user:
                     try:
@@ -64,7 +64,7 @@ class EventStreamHandler(BaseHandler):
                     yield self.distributor.fire(
                         "started_user_eventstream", auth_user
                     )
-            self._streams_per_user[auth_user] += 1
+                self._streams_per_user[auth_user] += 1
 
             if pagin_config.from_token is None:
                 pagin_config.from_token = None
@@ -92,27 +92,28 @@ class EventStreamHandler(BaseHandler):
             defer.returnValue(chunk)
 
         finally:
-            self._streams_per_user[auth_user] -= 1
-            if not self._streams_per_user[auth_user]:
-                del self._streams_per_user[auth_user]
-
-                # 10 seconds of grace to allow the client to reconnect again
-                #   before we think they're gone
-                def _later():
-                    logger.debug(
-                        "_later stopped_user_eventstream %s", auth_user
-                    )
+            if affect_presence:
+                self._streams_per_user[auth_user] -= 1
+                if not self._streams_per_user[auth_user]:
+                    del self._streams_per_user[auth_user]
+
+                    # 10 seconds of grace to allow the client to reconnect again
+                    #   before we think they're gone
+                    def _later():
+                        logger.debug(
+                            "_later stopped_user_eventstream %s", auth_user
+                        )
 
-                    self._stop_timer_per_user.pop(auth_user, None)
+                        self._stop_timer_per_user.pop(auth_user, None)
 
-                    yield self.distributor.fire(
-                        "stopped_user_eventstream", auth_user
-                    )
+                        yield self.distributor.fire(
+                            "stopped_user_eventstream", auth_user
+                        )
 
-                logger.debug("Scheduling _later: for %s", auth_user)
-                self._stop_timer_per_user[auth_user] = (
-                    self.clock.call_later(30, _later)
-                )
+                    logger.debug("Scheduling _later: for %s", auth_user)
+                    self._stop_timer_per_user[auth_user] = (
+                        self.clock.call_later(30, _later)
+                    )
 
 
 class EventHandler(BaseHandler):