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

Commit

Permalink
Fix grammar and document get_current_users_in_room (#4998)
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 authored Apr 3, 2019
1 parent e4d473d commit 4a4d5c4
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.d/4998.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix grammar in get_current_users_in_room and give it a docstring.
4 changes: 2 additions & 2 deletions synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _create_association(self, room_alias, room_id, servers=None, creator=None):
# TODO(erikj): Add transactions.
# TODO(erikj): Check if there is a current association.
if not servers:
users = yield self.state.get_current_user_in_room(room_id)
users = yield self.state.get_current_users_in_room(room_id)
servers = set(get_domain_from_id(u) for u in users)

if not servers:
Expand Down Expand Up @@ -268,7 +268,7 @@ def get_association(self, room_alias):
Codes.NOT_FOUND
)

users = yield self.state.get_current_user_in_room(room_id)
users = yield self.state.get_current_users_in_room(room_id)
extra_servers = set(get_domain_from_id(u) for u in users)
servers = set(extra_servers) | set(servers)

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_stream(self, auth_user_id, pagin_config, timeout=0,
# Send down presence.
if event.state_key == auth_user_id:
# Send down presence for everyone in the room.
users = yield self.state.get_current_user_in_room(event.room_id)
users = yield self.state.get_current_users_in_room(event.room_id)
states = yield presence_handler.get_states(
users,
as_event=True,
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_joined_members(self, requester, room_id):
"Getting joined members after leaving is not implemented"
)

users_with_profile = yield self.state.get_current_user_in_room(room_id)
users_with_profile = yield self.state.get_current_users_in_room(room_id)

# If this is an AS, double check that they are allowed to see the members.
# This can either be because the AS user is in the room or because there
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def _on_user_joined_room(self, room_id, user_id):
# TODO: Check that this is actually a new server joining the
# room.

user_ids = yield self.state.get_current_user_in_room(room_id)
user_ids = yield self.state.get_current_users_in_room(room_id)
user_ids = list(filter(self.is_mine_id, user_ids))

states = yield self.current_state_for_users(user_ids)
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/room_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_order_for_room(room_id):
if not latest_event_ids:
return

joined_users = yield self.state_handler.get_current_user_in_room(
joined_users = yield self.state_handler.get_current_users_in_room(
room_id, latest_event_ids,
)

Expand Down
8 changes: 4 additions & 4 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,11 @@ def _generate_sync_entry_for_device_list(self, sync_result_builder,
# TODO: Be more clever than this, i.e. remove users who we already
# share a room with?
for room_id in newly_joined_rooms:
joined_users = yield self.state.get_current_user_in_room(room_id)
joined_users = yield self.state.get_current_users_in_room(room_id)
newly_joined_users.update(joined_users)

for room_id in newly_left_rooms:
left_users = yield self.state.get_current_user_in_room(room_id)
left_users = yield self.state.get_current_users_in_room(room_id)
newly_left_users.update(left_users)

# TODO: Check that these users are actually new, i.e. either they
Expand Down Expand Up @@ -1213,7 +1213,7 @@ def _generate_sync_entry_for_presence(self, sync_result_builder, newly_joined_ro

extra_users_ids = set(newly_joined_users)
for room_id in newly_joined_rooms:
users = yield self.state.get_current_user_in_room(room_id)
users = yield self.state.get_current_users_in_room(room_id)
extra_users_ids.update(users)
extra_users_ids.discard(user.to_string())

Expand Down Expand Up @@ -1855,7 +1855,7 @@ def get_rooms_for_user_at(self, user_id, stream_ordering):
extrems = yield self.store.get_forward_extremeties_for_room(
room_id, stream_ordering,
)
users_in_room = yield self.state.get_current_user_in_room(
users_in_room = yield self.state.get_current_users_in_room(
room_id, extrems,
)
if user_id in users_in_room:
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _push_update(self, member, typing):
@defer.inlineCallbacks
def _push_remote(self, member, typing):
try:
users = yield self.state.get_current_user_in_room(member.room_id)
users = yield self.state.get_current_users_in_room(member.room_id)
self._member_last_federation_poke[member] = self.clock.time_msec()

now = self.clock.time_msec()
Expand Down Expand Up @@ -261,7 +261,7 @@ def _recv_edu(self, origin, content):
)
return

users = yield self.state.get_current_user_in_room(room_id)
users = yield self.state.get_current_users_in_room(room_id)
domains = set(get_domain_from_id(u) for u in users)

if self.server_name in domains:
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _handle_room_publicity_change(self, room_id, prev_event_id, event_id, typ):
# ignore the change
return

users_with_profile = yield self.state.get_current_user_in_room(room_id)
users_with_profile = yield self.state.get_current_users_in_room(room_id)

# Remove every user from the sharing tables for that room.
for user_id in iterkeys(users_with_profile):
Expand Down Expand Up @@ -325,7 +325,7 @@ def _handle_new_user(self, room_id, user_id, profile):
room_id
)
# Now we update users who share rooms with users.
users_with_profile = yield self.state.get_current_user_in_room(room_id)
users_with_profile = yield self.state.get_current_users_in_room(room_id)

if is_public:
yield self.store.add_users_in_public_rooms(room_id, (user_id,))
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def on_POST(self, request, room_id):
# desirable in case the first attempt at blocking the room failed below.
yield self.store.block_room(room_id, requester_user_id)

users = yield self.state.get_current_user_in_room(room_id)
users = yield self.state.get_current_users_in_room(room_id)
kicked_users = []
failed_to_kick_users = []
for user_id in users:
Expand Down
15 changes: 13 additions & 2 deletions synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,21 @@ def get_current_state_ids(self, room_id, latest_event_ids=None):
defer.returnValue(state)

@defer.inlineCallbacks
def get_current_user_in_room(self, room_id, latest_event_ids=None):
def get_current_users_in_room(self, room_id, latest_event_ids=None):
"""
Get the users who are currently in a room.
Args:
room_id (str): The ID of the room.
latest_event_ids (List[str]|None): Precomputed list of latest
event IDs. Will be computed if None.
Returns:
Deferred[Dict[str,ProfileInfo]]: Dictionary of user IDs to their
profileinfo.
"""
if not latest_event_ids:
latest_event_ids = yield self.store.get_latest_event_ids_in_room(room_id)
logger.debug("calling resolve_state_groups from get_current_user_in_room")
logger.debug("calling resolve_state_groups from get_current_users_in_room")
entry = yield self.resolve_state_groups_for_events(room_id, latest_event_ids)
joined_users = yield self.store.get_joined_users_from_state(room_id, entry)
defer.returnValue(joined_users)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _get_next_batch(txn):
room_id
)

users_with_profile = yield state.get_current_user_in_room(room_id)
users_with_profile = yield state.get_current_users_in_room(room_id)
user_ids = set(users_with_profile)

# Update each user in the user directory.
Expand Down
4 changes: 2 additions & 2 deletions tests/handlers/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def get_joined_hosts_for_room(room_id):

self.datastore.get_joined_hosts_for_room = get_joined_hosts_for_room

def get_current_user_in_room(room_id):
def get_current_users_in_room(room_id):
return set(str(u) for u in self.room_members)
hs.get_state_handler().get_current_user_in_room = get_current_user_in_room
hs.get_state_handler().get_current_users_in_room = get_current_users_in_room

self.datastore.get_user_directory_stream_pos.return_value = (
# we deliberately return a non-None stream pos to avoid doing an initial_spam
Expand Down

0 comments on commit 4a4d5c4

Please sign in to comment.