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

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Velten committed Dec 12, 2023
1 parent 66debd9 commit 06c46b3
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions synapse/server_notices/server_notices_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, hs: "HomeServer"):
self._room_member_handler = hs.get_room_member_handler()
self._event_creation_handler = hs.get_event_creation_handler()
self._message_handler = hs.get_message_handler()
self._storage_controllers = hs.get_storage_controllers()
self._is_mine_id = hs.is_mine_id
self._server_name = hs.hostname

Expand Down Expand Up @@ -302,11 +303,12 @@ async def _update_notice_user_profile_if_changed(

assert self.server_notices_mxid is not None

notice_user_data_in_room = await self._message_handler.get_room_data(
create_requester(self.server_notices_mxid),
room_id,
EventTypes.Member,
self.server_notices_mxid,
notice_user_data_in_room = (
await self._storage_controllers.state.get_current_state_event(
room_id,
EventTypes.Member,
self.server_notices_mxid,
)
)

assert notice_user_data_in_room is not None
Expand All @@ -333,7 +335,6 @@ async def _update_room_info(
info_event_type: str,
info_content_key: str,
info_value: Optional[str],
if_changed: Optional[bool] = True,
) -> None:
"""
Updates a specific notice room's info if it's different from what is set.
Expand All @@ -344,27 +345,23 @@ async def _update_room_info(
info_event_type: The event type holding the specific info
info_content_key: The key containing the specific info in the event's content
info_value: The expected value for the specific info
if_changed: Try to read the info first and does not send the event if it's already the same
"""
if if_changed:
room_info_event = await self._message_handler.get_room_data(
requester,
room_id,
info_event_type,
"",
)
room_info_event = await self._storage_controllers.state.get_current_state_event(
room_id,
info_event_type,
"",
)

existing_info_value = None
if room_info_event:
existing_info_value = room_info_event.get(info_content_key)
if existing_info_value == info_value:
return
if not existing_info_value and not info_value:
# A missing `info_value` can either be represented by a None
# or an empty string, so we assume that if they're both falsey
# they're equivalent.
return
return
existing_info_value = None
if room_info_event:
existing_info_value = room_info_event.get(info_content_key)
if existing_info_value == info_value:
return
if not existing_info_value and not info_value:
# A missing `info_value` can either be represented by a None
# or an empty string, so we assume that if they're both falsey
# they're equivalent.
return

if info_value is None:
info_value = ""
Expand Down

0 comments on commit 06c46b3

Please sign in to comment.