From 42ac5f0c1ae560e64dd5e9335d7f16b83fdabda4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 19 Feb 2016 12:07:49 +0000 Subject: [PATCH 1/2] Only send presence updates to remote hosts if user is ours --- synapse/handlers/presence.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 44bdc97cc..451fc70b3 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -428,13 +428,21 @@ class PresenceHandler(BaseHandler): hosts_to_states = {} for room_id, states in room_ids_to_states.items(): + local_states = filter(self.hs.is_mine_id, states) + if not local_states: + continue + hosts = yield self.store.get_joined_hosts_for_room(room_id) for host in hosts: - hosts_to_states.setdefault(host, []).extend(states) + hosts_to_states.setdefault(host, []).extend(local_states) for user_id, states in users_to_states.items(): + local_states = filter(self.hs.is_mine_id, states) + if not local_states: + continue + host = UserID.from_string(user_id).domain - hosts_to_states.setdefault(host, []).extend(states) + hosts_to_states.setdefault(host, []).extend(local_states) # TODO: de-dup hosts_to_states, as a single host might have multiple # of same presence From 3dbaeef58cf33f0399f40a2aa3c6205fdbe5dbd8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 19 Feb 2016 12:27:35 +0000 Subject: [PATCH 2/2] Correctly filter states --- synapse/handlers/presence.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 451fc70b3..aed640450 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -428,7 +428,7 @@ class PresenceHandler(BaseHandler): hosts_to_states = {} for room_id, states in room_ids_to_states.items(): - local_states = filter(self.hs.is_mine_id, states) + local_states = filter(lambda s: self.hs.is_mine_id(s.user_id), states) if not local_states: continue @@ -437,7 +437,7 @@ class PresenceHandler(BaseHandler): hosts_to_states.setdefault(host, []).extend(local_states) for user_id, states in users_to_states.items(): - local_states = filter(self.hs.is_mine_id, states) + local_states = filter(lambda s: self.hs.is_mine_id(s.user_id), states) if not local_states: continue