mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 14:24:55 -04:00
Fix some comments and types in service notices (#7996)
This commit is contained in:
parent
394be6a0e6
commit
d1008fe949
7 changed files with 56 additions and 59 deletions
|
@ -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
|
||||
|
||||
|
@ -50,20 +52,21 @@ class ServerNoticesManager(object):
|
|||
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,
|
||||
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:
|
||||
Deferred[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)
|
||||
|
@ -89,17 +92,17 @@ class ServerNoticesManager(object):
|
|||
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")
|
||||
|
@ -163,7 +166,7 @@ class ServerNoticesManager(object):
|
|||
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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue