Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix bug where we sent remote presence states to remote servers #9850

Merged
merged 2 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/9850.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental support for handling presence on a worker.
4 changes: 4 additions & 0 deletions synapse/federation/sender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ def send_presence_to_destinations(
# No-op if presence is disabled.
return

# Ensure we only send out presence states for local users.
for state in states:
assert self.is_mine_id(state.user_id)

for destination in destinations:
if destination == self.server_name:
continue
Expand Down
11 changes: 8 additions & 3 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def __init__(self, hs: "HomeServer"):
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:
Expand Down Expand Up @@ -261,7 +262,8 @@ async def maybe_send_presence_to_interested_destinations(
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:
Expand All @@ -270,6 +272,11 @@ async def maybe_send_presence_to_interested_destinations(
# 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,
Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand Down