summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-08-28 16:43:55 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-08-28 16:43:55 +0100
commitefc5f3440dc033d9d1713eaa7159b75689704d6c (patch)
treea9724d7c7191bc8ec6e6acfd5268540c66016c96 /synapse
parentAbility to assert a DeferredMockCallable has received no calls (diff)
downloadsynapse-efc5f3440dc033d9d1713eaa7159b75689704d6c.tar.xz
Only send presence "poll"/"unpoll" EDUs when changing from/to zero remotes
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/presence.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 1b3cdcc38c..bef1508892 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -437,16 +437,22 @@ class PresenceHandler(BaseHandler):
         )
 
     def _start_polling_remote(self, user, domain, remoteusers):
+        to_poll = set()
+
         for u in remoteusers:
             if u not in self._remote_recvmap:
                 self._remote_recvmap[u] = set()
+                to_poll.add(u)
 
             self._remote_recvmap[u].add(user)
 
+        if not to_poll:
+            return defer.succeed(None)
+
         return self.federation.send_edu(
             destination=domain,
             edu_type="m.presence",
-            content={"poll": [u.to_string() for u in remoteusers]}
+            content={"poll": [u.to_string() for u in to_poll]}
         )
 
     def stop_polling_presence(self, user, target_user=None):
@@ -489,16 +495,22 @@ class PresenceHandler(BaseHandler):
                 del self._local_pushmap[localpart]
 
     def _stop_polling_remote(self, user, domain, remoteusers):
+        to_unpoll = set()
+
         for u in remoteusers:
             self._remote_recvmap[u].remove(user)
 
             if not self._remote_recvmap[u]:
                 del self._remote_recvmap[u]
+                to_unpoll.add(u)
+
+        if not to_unpoll:
+            return defer.succeed(None)
 
         return self.federation.send_edu(
             destination=domain,
             edu_type="m.presence",
-            content={"unpoll": [u.to_string() for u in remoteusers]}
+            content={"unpoll": [u.to_string() for u in to_unpoll]}
         )
 
     @defer.inlineCallbacks