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

Fix some comments and types in service notices #7996

Merged
merged 5 commits into from
Jul 31, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions synapse/server_notices/server_notices_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from typing import Optional

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

Expand Down Expand Up @@ -50,20 +52,21 @@ def is_enabled(self):
return self._config.server_notices_mxid is not None

async def send_notice(
self, user_id, event_content, type=EventTypes.Message, state_key=None
):
self,
user_id: str,
event_content: dict,
type: str = EventTypes.Message,
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
state_key: Optional[bool] = None,
) -> EventBase:
"""Send a notice to the given user

Creates the server notices room, if none exists.

Args:
user_id (str): mxid of user to send event to.
event_content (dict): content of event to send
type(EventTypes): type of event
is_state_event(bool): Is the event a state event

Returns:
FrozenEvent
user_id: mxid of user to send event to.
event_content: content of event to send
type: type of event
is_state_event: Is the event a state event
"""
room_id = await self.get_or_create_notice_room_for_user(user_id)
await self.maybe_invite_user_to_room(user_id, room_id)
Expand All @@ -89,17 +92,17 @@ async def send_notice(
return event

@cached()
async def get_or_create_notice_room_for_user(self, user_id):
async def get_or_create_notice_room_for_user(self, user_id: str) -> str:
"""Get the room for notices for a given user

If we have not yet created a notice room for this user, create it, but don't
invite the user to it.

Args:
user_id (str): complete user id for the user we want a room for
user_id: complete user id for the user we want a room for

Returns:
str: room id of notice room.
room id of notice room.
"""
if not self.is_enabled():
raise Exception("Server notices not enabled")
Expand Down Expand Up @@ -163,7 +166,7 @@ async def get_or_create_notice_room_for_user(self, user_id):
logger.info("Created server notices room %s for %s", room_id, user_id)
return room_id

async def maybe_invite_user_to_room(self, user_id: str, room_id: str):
async def maybe_invite_user_to_room(self, user_id: str, room_id: str) -> None:
"""Invite the given user to the given server room, unless the user has already
joined or been invited to it.

Expand Down