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

Commit

Permalink
use initial_state
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Velten committed Dec 7, 2023
1 parent f0e96e8 commit 4fdfa05
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions synapse/server_notices/server_notices_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from synapse.api.constants import EventTypes, Membership, RoomCreationPreset
from synapse.events import EventBase
from synapse.types import Requester, StreamKeyType, UserID, create_requester
from synapse.types import JsonDict, Requester, StreamKeyType, UserID, create_requester
from synapse.util.caches.descriptors import cached

if TYPE_CHECKING:
Expand Down Expand Up @@ -199,7 +199,7 @@ async def get_or_create_notice_room_for_user(self, user_id: str) -> str:
"avatar_url": self._config.servernotices.server_notices_mxid_avatar_url,
}

room_config = {
room_config: JsonDict = {
"preset": RoomCreationPreset.PRIVATE_CHAT,
"power_level_content_override": {"users_default": -10},
}
Expand All @@ -208,6 +208,16 @@ async def get_or_create_notice_room_for_user(self, user_id: str) -> str:
room_config["name"] = self._config.servernotices.server_notices_room_name
if self._config.servernotices.server_notices_room_topic:
room_config["topic"] = self._config.servernotices.server_notices_room_topic
if self._config.servernotices.server_notices_room_avatar_url:
room_config["initial_state"] = [
{
"type": EventTypes.RoomAvatar,
"state_key": "",
"content": {
"url": self._config.servernotices.server_notices_room_avatar_url,
},
}
]

# `ignore_forced_encryption` is used to bypass `encryption_enabled_by_default_for_room_type`
# setting if it set, since the server notices will not be encrypted anyway.
Expand All @@ -219,18 +229,6 @@ async def get_or_create_notice_room_for_user(self, user_id: str) -> str:
ignore_forced_encryption=True,
)

# Room avatar can't be set at creation time so let's just send an event for that
if self._config.servernotices.server_notices_room_avatar_url:
await self._update_room_info(
requester,
room_id,
EventTypes.RoomAvatar,
"url",
self._config.servernotices.server_notices_room_avatar_url,
# Since we just created the room there is no need to check current value
if_changed=False,
)

self.maybe_get_notice_room_for_user.invalidate((user_id,))

max_id = await self._account_data_handler.add_tag_to_room(
Expand Down

0 comments on commit 4fdfa05

Please sign in to comment.