Skip to content

Commit

Permalink
Convert synapse.server_notices to async/await. (matrix-org#7394)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored and phil-flex committed Jun 16, 2020
1 parent 9c7e95a commit f039751
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.d/7394.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert synapse.server_notices to async/await.
16 changes: 6 additions & 10 deletions synapse/server_notices/resource_limits_server_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

from six import iteritems

from twisted.internet import defer

from synapse.api.constants import (
EventTypes,
LimitBlockingTypes,
Expand Down Expand Up @@ -167,29 +165,27 @@ async def _apply_limit_block_notification(
user_id, content, EventTypes.Pinned, ""
)

@defer.inlineCallbacks
def _check_and_set_tags(self, user_id, room_id):
async def _check_and_set_tags(self, user_id, room_id):
"""
Since server notices rooms were originally not with tags,
important to check that tags have been set correctly
Args:
user_id(str): the user in question
room_id(str): the server notices room for that user
"""
tags = yield self._store.get_tags_for_room(user_id, room_id)
tags = await self._store.get_tags_for_room(user_id, room_id)
need_to_set_tag = True
if tags:
if SERVER_NOTICE_ROOM_TAG in tags:
# tag already present, nothing to do here
need_to_set_tag = False
if need_to_set_tag:
max_id = yield self._store.add_tag_to_room(
max_id = await self._store.add_tag_to_room(
user_id, room_id, SERVER_NOTICE_ROOM_TAG, {}
)
self._notifier.on_new_event("account_data_key", max_id, users=[user_id])

@defer.inlineCallbacks
def _is_room_currently_blocked(self, room_id):
async def _is_room_currently_blocked(self, room_id):
"""
Determines if the room is currently blocked
Expand All @@ -207,7 +203,7 @@ def _is_room_currently_blocked(self, room_id):
currently_blocked = False
pinned_state_event = None
try:
pinned_state_event = yield self._state.get_current_state(
pinned_state_event = await self._state.get_current_state(
room_id, event_type=EventTypes.Pinned
)
except AuthError:
Expand All @@ -218,7 +214,7 @@ def _is_room_currently_blocked(self, room_id):
if pinned_state_event is not None:
referenced_events = list(pinned_state_event.content.get("pinned", []))

events = yield self._store.get_events(referenced_events)
events = await self._store.get_events(referenced_events)
for event_id, event in iteritems(events):
if event.type != EventTypes.Message:
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def prepare(self, reactor, clock, hs):
return_value=defer.succeed("!something:localhost")
)
self._rlsn._store.add_tag_to_room = Mock(return_value=defer.succeed(None))
self._rlsn._store.get_tags_for_room = Mock(return_value={})
self._rlsn._store.get_tags_for_room = Mock(return_value=defer.succeed({}))
self.hs.config.admin_contact = "mailto:[email protected]"

def test_maybe_send_server_notice_to_user_flag_off(self):
Expand Down

0 comments on commit f039751

Please sign in to comment.