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
Add a test for sending all local online presence over federation
  • Loading branch information
anoadragon453 committed Mar 26, 2021
commit 6daf640b919f7003d48d42b046203c5d9ee97b09
62 changes: 59 additions & 3 deletions tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# limitations under the License.
from mock import Mock

from synapse.api.constants import EduTypes
from synapse.events import EventBase
from synapse.federation.units import Transaction
from synapse.handlers.presence import UserPresenceState
from synapse.rest import admin
from synapse.rest.client.v1 import login, presence, room
Expand All @@ -25,10 +27,10 @@
send_presence_update,
sync_presence,
)
from tests.unittest import HomeserverTestCase, override_config
from tests.unittest import FederatingHomeserverTestCase, override_config


class ModuleApiTestCase(HomeserverTestCase):
class ModuleApiTestCase(FederatingHomeserverTestCase):
servlets = [
admin.register_servlets,
login.register_servlets,
Expand All @@ -41,6 +43,11 @@ def prepare(self, reactor, clock, homeserver):
self.module_api = homeserver.get_module_api()
self.event_creation_handler = homeserver.get_event_creation_handler()

def make_homeserver(self, reactor, clock):
return self.setup_test_homeserver(
federation_transport_client=Mock(spec=["send_transaction"]),
)

def test_can_register_user(self):
"""Tests that an external module can register a user"""
# Register a new user
Expand Down Expand Up @@ -226,10 +233,12 @@ def test_public_rooms(self):
"users_who_should_receive_all_presence": [
"@presence_gobbler1:test",
"@presence_gobbler2:test",
"@far_away_person:island",
]
},
}
}
},
"send_federation": True,
}
)
def test_send_local_online_presence_to(self):
Expand Down Expand Up @@ -302,3 +311,50 @@ def test_send_local_online_presence_to(self):
self.assertEqual(len(presence_updates), 3)
presence_updates = sync_presence(self, self.presence_receiving_user_two_id)
self.assertEqual(len(presence_updates), 3)

# Test that sending to a remote user works
remote_user_id = "@far_away_person:island"

# Note that due to the remote user being in our module's
# users_who_should_receive_all_presence config, they would have
# received user presence updates already.
#
# Thus we reset the mock, and try sending all online local user
# presence again
self.hs.get_federation_transport_client().send_transaction.reset_mock()

# Track the outgoing presence on the federation client
self.get_success(
self.module_api.send_local_online_presence_to([remote_user_id])
)

# Check that the expected presence updates were sent
expected_users = [
self.other_user_id,
self.presence_receiving_user_one_id,
self.presence_receiving_user_two_id,
]

calls = (
self.hs.get_federation_transport_client().send_transaction.call_args_list
)
for call in calls:
federation_transaction = call.args[0] # type: Transaction

# Get the sent EDUs in this transaction
edus = federation_transaction.get_dict()["edus"]

for edu in edus:
# Make sure we're only checking presence-type EDUs
if edu["edu_type"] != EduTypes.Presence:
continue

# EDUs can contain multiple presence updates
for presence_update in edu["content"]["push"]:
# Check for presence updates that contain the user IDs we're after
expected_users.remove(presence_update["user_id"])

# Ensure that no offline states are being sent out
self.assertNotEqual(presence_update["presence"], "offline")

self.assertEqual(len(expected_users), 0)