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

Add a Synapse Module for configuring presence update routing #9491

Merged
merged 35 commits into from
Apr 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
de8c33e
Add documentation for implementing a PresenceRouter module
anoadragon453 Mar 17, 2021
09eb6fd
Clean up presence config, allow specifying a presence_router module
anoadragon453 Mar 17, 2021
5751f6d
Add a built-in PresenceRouter class
anoadragon453 Mar 17, 2021
3600d63
Modify `get_interested_parties` and `get_interested_remotes` to query…
anoadragon453 Mar 18, 2021
f62e385
Add a func to ModuleApi to send all local online user presence to a s…
anoadragon453 Mar 17, 2021
2a0c785
Update PresenceHandler to call PresenceRouter methods when applicable
anoadragon453 Mar 18, 2021
08f39cf
Update method calls to thread presence_router through to presence han…
anoadragon453 Mar 18, 2021
5c5eb45
Add tests for PresenceRouter and new module_api method
anoadragon453 Mar 18, 2021
ff6d051
Changelog
anoadragon453 Mar 18, 2021
b67b071
Remove Literal as it's broken on py35-olddeps
anoadragon453 Mar 18, 2021
41f9cd1
Social distancing for example module
anoadragon453 Mar 22, 2021
5fc716c
Specify PresenceRouter class method definitions up front
anoadragon453 Mar 22, 2021
a2a60e0
Add docstring to (and remove useless arg from) method
anoadragon453 Mar 22, 2021
997a81b
Raise if required PresenceRouter methods are not implemented
anoadragon453 Mar 23, 2021
41537b9
Note that AS's are not currently supported
anoadragon453 Mar 25, 2021
4fcd817
Don't just blindly copy our PoC code
anoadragon453 Mar 26, 2021
744bb53
typo fix
anoadragon453 Mar 26, 2021
6daf640
Add a test for sending all local online presence over federation
anoadragon453 Mar 26, 2021
5e2a047
Fix burst federation presence sending implementation
anoadragon453 Mar 26, 2021
37d30d7
Fix cyclic dependency import
anoadragon453 Mar 26, 2021
1dfc8cc
Only load federation_sender where it's needed in ModuleApi
anoadragon453 Mar 29, 2021
42a7db2
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/pre…
anoadragon453 Mar 29, 2021
23c5b93
presence != federation
anoadragon453 Mar 29, 2021
7c1eedb
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/pre…
anoadragon453 Mar 29, 2021
5549f52
Make "ALL" return value a constant
anoadragon453 Mar 31, 2021
6fae9f3
Wording fixes
anoadragon453 Mar 31, 2021
2f16ed0
Refactor _filter_all_presence_updates_for_user; always filter through PR
anoadragon453 Mar 31, 2021
36a7bd2
Make ModuleApi._send_full_presence_to_local_users private
anoadragon453 Mar 31, 2021
9186191
Add a couple tests for send_local_online_presence_to w/o a PresenceRo…
anoadragon453 Mar 31, 2021
ac4b0ff
Move PresenceRouter module_api test to test_presence_router
anoadragon453 Mar 31, 2021
6e42612
Refactor PresenceRouter tests
anoadragon453 Mar 31, 2021
25de4c1
Sort some eyes
anoadragon453 Apr 1, 2021
a1a52f4
Some clarifications to the module documentation
anoadragon453 Apr 6, 2021
e538126
Clarify text in a comment and docstring
anoadragon453 Apr 6, 2021
9ddbaa8
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/pre…
anoadragon453 Apr 6, 2021
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
Prev Previous commit
Next Next commit
Modify get_interested_parties and get_interested_remotes to query…
… PresenceRouter

This commit asks the PresenceRouter for any users - in addition to those
from users that they share a room with - that should receive the given
presence updates.

These methods are called when routing new presence updates around as
they come in.

* `get_interested_parties` is called when figuring out which local and
remote users to send presence to. For local users, their sync streams
will be woken up.
* `get_interested_remotes` is specifically for figuring out which remote
user(s) a given presence update needs to go to.
  • Loading branch information
anoadragon453 committed Mar 25, 2021
commit 3600d632b7c8b4e4414614354ac0b1a099c68050
31 changes: 23 additions & 8 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,14 +1314,15 @@ def handle_update(prev_state, new_state, is_mine, wheel_timer, now):


async def get_interested_parties(
store: DataStore, states: List[UserPresenceState]
store: DataStore, presence_router: PresenceRouter, states: List[UserPresenceState]
) -> Tuple[Dict[str, List[UserPresenceState]], Dict[str, List[UserPresenceState]]]:
"""Given a list of states return which entities (rooms, users)
are interested in the given states.

Args:
store
states
store: The homeserver's data store.
presence_router: A module for augmenting the destinations for presence updates.
states: A list of incoming user presence updates.

Returns:
A 2-tuple of `(room_ids_to_states, users_to_states)`,
Expand All @@ -1337,21 +1338,33 @@ async def get_interested_parties(
# Always notify self
users_to_states.setdefault(state.user_id, []).append(state)

# Ask a presence routing module for any additional parties if one
# is loaded.
router_users_to_states = await presence_router.get_users_for_states(states)

# Update the dictionaries with additional destinations and state to send
for user_id, user_states in router_users_to_states.items():
users_to_states.setdefault(user_id, []).extend(user_states)

return room_ids_to_states, users_to_states


async def get_interested_remotes(
store: DataStore, states: List[UserPresenceState], state_handler: StateHandler
store: DataStore,
presence_router: PresenceRouter,
states: List[UserPresenceState],
state_handler: StateHandler,
) -> List[Tuple[Collection[str], List[UserPresenceState]]]:
"""Given a list of presence states figure out which remote servers
should be sent which.

All the presence states should be for local users only.

Args:
store
states
state_handler
store: The homeserver's data store.
presence_router: A module for augmenting the destinations for presence updates.
states: A list of incoming user presence updates.
state_handler:

Returns:
A list of 2-tuples of destinations and states, where for
Expand All @@ -1363,7 +1376,9 @@ async def get_interested_remotes(
# First we look up the rooms each user is in (as well as any explicit
# subscriptions), then for each distinct room we look up the remote
# hosts in those rooms.
room_ids_to_states, users_to_states = await get_interested_parties(store, states)
room_ids_to_states, users_to_states = await get_interested_parties(
store, presence_router, states
)

for room_id, states in room_ids_to_states.items():
hosts = await state_handler.get_current_hosts_in_room(room_id)
Expand Down