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

Commit

Permalink
Port PresenceHandler to async/await (#6991)
Browse files Browse the repository at this point in the history
erikjohnston authored Feb 26, 2020
1 parent 7728d87 commit 1f773ee
Showing 7 changed files with 113 additions and 115 deletions.
1 change: 1 addition & 0 deletions changelog.d/6991.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port `synapse.handlers.presence` to async/await.
5 changes: 2 additions & 3 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
@@ -1016,11 +1016,10 @@ def _notify():
# matters as sometimes presence code can take a while.
run_in_background(self._bump_active_time, requester.user)

@defer.inlineCallbacks
def _bump_active_time(self, user):
async def _bump_active_time(self, user):
try:
presence = self.hs.get_presence_handler()
yield presence.bump_presence_active_time(user)
await presence.bump_presence_active_time(user)
except Exception:
logger.exception("Error bumping presence active time")

192 changes: 87 additions & 105 deletions synapse/handlers/presence.py

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion synapse/replication/tcp/resource.py
Original file line number Diff line number Diff line change
@@ -323,7 +323,11 @@ def lost_connection(self, connection):

# We need to tell the presence handler that the connection has been
# lost so that it can handle any ongoing syncs on that connection.
self.presence_handler.update_external_syncs_clear(connection.conn_id)
run_as_background_process(
"update_external_syncs_clear",
self.presence_handler.update_external_syncs_clear,
connection.conn_id,
)


def _batch_updates(updates):
5 changes: 5 additions & 0 deletions synapse/server.pyi
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import twisted.internet
import synapse.api.auth
import synapse.config.homeserver
import synapse.crypto.keyring
import synapse.federation.federation_server
import synapse.federation.sender
import synapse.federation.transport.client
import synapse.handlers
@@ -107,5 +108,9 @@ class HomeServer(object):
self,
) -> synapse.replication.tcp.client.ReplicationClientHandler:
pass
def get_federation_registry(
self,
) -> synapse.federation.federation_server.FederationHandlerRegistry:
pass
def is_mine_id(self, domain_id: str) -> bool:
pass
18 changes: 12 additions & 6 deletions tests/handlers/test_presence.py
Original file line number Diff line number Diff line change
@@ -494,8 +494,10 @@ def test_remote_joins(self):
self.helper.join(room_id, "@test2:server")

# Mark test2 as online, test will be offline with a last_active of 0
self.presence_handler.set_state(
UserID.from_string("@test2:server"), {"presence": PresenceState.ONLINE}
self.get_success(
self.presence_handler.set_state(
UserID.from_string("@test2:server"), {"presence": PresenceState.ONLINE}
)
)
self.reactor.pump([0]) # Wait for presence updates to be handled

@@ -543,14 +545,18 @@ def test_remote_gets_presence_when_local_user_joins(self):
room_id = self.helper.create_room_as(self.user_id)

# Mark test as online
self.presence_handler.set_state(
UserID.from_string("@test:server"), {"presence": PresenceState.ONLINE}
self.get_success(
self.presence_handler.set_state(
UserID.from_string("@test:server"), {"presence": PresenceState.ONLINE}
)
)

# Mark test2 as online, test will be offline with a last_active of 0.
# Note we don't join them to the room yet
self.presence_handler.set_state(
UserID.from_string("@test2:server"), {"presence": PresenceState.ONLINE}
self.get_success(
self.presence_handler.set_state(
UserID.from_string("@test2:server"), {"presence": PresenceState.ONLINE}
)
)

# Add servers to the room
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -183,6 +183,7 @@ commands = mypy \
synapse/events/spamcheck.py \
synapse/federation/sender \
synapse/federation/transport \
synapse/handlers/presence.py \
synapse/handlers/sync.py \
synapse/handlers/ui_auth \
synapse/logging/ \

0 comments on commit 1f773ee

Please sign in to comment.