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

This commit is contained in:
Erik Johnston 2021-04-20 13:37:54 +01:00 committed by GitHub
parent 495b214f4f
commit db70435de7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

1
changelog.d/9850.feature Normal file
View File

@ -0,0 +1 @@
Add experimental support for handling presence on a worker.

View File

@ -539,6 +539,10 @@ class FederationSender(AbstractFederationSender):
# No-op if presence is disabled. # No-op if presence is disabled.
return 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: for destination in destinations:
if destination == self.server_name: if destination == self.server_name:
continue continue

View File

@ -125,6 +125,7 @@ class BasePresenceHandler(abc.ABC):
self.store = hs.get_datastore() self.store = hs.get_datastore()
self.presence_router = hs.get_presence_router() self.presence_router = hs.get_presence_router()
self.state = hs.get_state_handler() self.state = hs.get_state_handler()
self.is_mine_id = hs.is_mine_id
self._federation = None self._federation = None
if hs.should_send_federation() or not hs.config.worker_app: if hs.should_send_federation() or not hs.config.worker_app:
@ -261,7 +262,8 @@ class BasePresenceHandler(abc.ABC):
self, states: List[UserPresenceState] self, states: List[UserPresenceState]
): ):
"""If this instance is a federation sender, send the states to all """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: if not self._send_federation:
@ -270,6 +272,11 @@ class BasePresenceHandler(abc.ABC):
# If this worker sends federation we must have a FederationSender. # If this worker sends federation we must have a FederationSender.
assert self._federation 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( hosts_and_states = await get_interested_remotes(
self.store, self.store,
self.presence_router, self.presence_router,
@ -292,7 +299,6 @@ class WorkerPresenceHandler(BasePresenceHandler):
def __init__(self, hs): def __init__(self, hs):
super().__init__(hs) super().__init__(hs)
self.hs = hs self.hs = hs
self.is_mine_id = hs.is_mine_id
self._presence_enabled = hs.config.use_presence self._presence_enabled = hs.config.use_presence
@ -492,7 +498,6 @@ class PresenceHandler(BasePresenceHandler):
def __init__(self, hs: "HomeServer"): def __init__(self, hs: "HomeServer"):
super().__init__(hs) super().__init__(hs)
self.hs = hs self.hs = hs
self.is_mine_id = hs.is_mine_id
self.server_name = hs.hostname self.server_name = hs.hostname
self.wheel_timer = WheelTimer() self.wheel_timer = WheelTimer()
self.notifier = hs.get_notifier() self.notifier = hs.get_notifier()