summary refs log tree commit diff
path: root/synapse/handlers/presence.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-04-20 13:37:54 +0100
committerGitHub <noreply@github.com>2021-04-20 13:37:54 +0100
commitdb70435de740b534936df75c435290a37dcc015f (patch)
tree1d68fd60daa7b10009ca3410c0aee4b3308737f8 /synapse/handlers/presence.py
parentFix (final) Bugbear violations (#9838) (diff)
downloadsynapse-db70435de740b534936df75c435290a37dcc015f.tar.xz
Fix bug where we sent remote presence states to remote servers (#9850)
Diffstat (limited to 'synapse/handlers/presence.py')
-rw-r--r--synapse/handlers/presence.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 6460eb9952..bd2382193f 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -125,6 +125,7 @@ class BasePresenceHandler(abc.ABC):
         self.store = hs.get_datastore()
         self.presence_router = hs.get_presence_router()
         self.state = hs.get_state_handler()
+        self.is_mine_id = hs.is_mine_id
 
         self._federation = None
         if hs.should_send_federation() or not hs.config.worker_app:
@@ -261,7 +262,8 @@ class BasePresenceHandler(abc.ABC):
         self, states: List[UserPresenceState]
     ):
         """If this instance is a federation sender, send the states to all
-        destinations that are interested.
+        destinations that are interested. Filters out any states for remote
+        users.
         """
 
         if not self._send_federation:
@@ -270,6 +272,11 @@ class BasePresenceHandler(abc.ABC):
         # If this worker sends federation we must have a FederationSender.
         assert self._federation
 
+        states = [s for s in states if self.is_mine_id(s.user_id)]
+
+        if not states:
+            return
+
         hosts_and_states = await get_interested_remotes(
             self.store,
             self.presence_router,
@@ -292,7 +299,6 @@ class WorkerPresenceHandler(BasePresenceHandler):
     def __init__(self, hs):
         super().__init__(hs)
         self.hs = hs
-        self.is_mine_id = hs.is_mine_id
 
         self._presence_enabled = hs.config.use_presence
 
@@ -492,7 +498,6 @@ class PresenceHandler(BasePresenceHandler):
     def __init__(self, hs: "HomeServer"):
         super().__init__(hs)
         self.hs = hs
-        self.is_mine_id = hs.is_mine_id
         self.server_name = hs.hostname
         self.wheel_timer = WheelTimer()
         self.notifier = hs.get_notifier()