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

Add type hints to the room member handler. #9631

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog.d/9631.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add additional type hints to the Homeserver object.
4 changes: 2 additions & 2 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ async def _join_rooms(self, user_id: str) -> None:

if RoomAlias.is_valid(r):
(
room_id,
room,
remote_room_hosts,
) = await room_member_handler.lookup_room_alias(room_alias)
room_id = room_id.to_string()
room_id = room.to_string()
else:
raise SynapseError(
400, "%s was not legal room ID or room alias" % (r,)
Expand Down
4 changes: 4 additions & 0 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ async def _user_left_room(self, target: UserID, room_id: str) -> None:
"""
raise NotImplementedError()

@abc.abstractmethod
async def forget(self, user: UserID, room_id: str) -> None:
raise NotImplementedError()

def ratelimit_invite(self, room_id: Optional[str], invitee_user_id: str):
"""Ratelimit invites by room and by target user.

Expand Down
10 changes: 8 additions & 2 deletions synapse/handlers/room_member_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

import logging
from typing import List, Optional, Tuple
from typing import TYPE_CHECKING, List, Optional, Tuple

from synapse.api.errors import SynapseError
from synapse.handlers.room_member import RoomMemberHandler
Expand All @@ -25,11 +25,14 @@
)
from synapse.types import Requester, UserID

if TYPE_CHECKING:
from synapse.app.homeserver import HomeServer

logger = logging.getLogger(__name__)


class RoomMemberWorkerHandler(RoomMemberHandler):
def __init__(self, hs):
def __init__(self, hs: "HomeServer"):
super().__init__(hs)

self._remote_join_client = ReplRemoteJoin.make_client(hs)
Expand Down Expand Up @@ -83,3 +86,6 @@ async def _user_left_room(self, target: UserID, room_id: str) -> None:
await self._notify_change_client(
user_id=target.to_string(), room_id=room_id, change="left"
)

async def forget(self, target: UserID, room_id: str) -> None:
raise RuntimeError("Cannot forget rooms on workers.")
4 changes: 2 additions & 2 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
RoomShutdownHandler,
)
from synapse.handlers.room_list import RoomListHandler
from synapse.handlers.room_member import RoomMemberMasterHandler
from synapse.handlers.room_member import RoomMemberHandler, RoomMemberMasterHandler
from synapse.handlers.room_member_worker import RoomMemberWorkerHandler
from synapse.handlers.search import SearchHandler
from synapse.handlers.set_password import SetPasswordHandler
Expand Down Expand Up @@ -630,7 +630,7 @@ def get_third_party_event_rules(self) -> ThirdPartyEventRules:
return ThirdPartyEventRules(self)

@cache_in_self
def get_room_member_handler(self):
def get_room_member_handler(self) -> RoomMemberHandler:
if self.config.worker_app:
return RoomMemberWorkerHandler(self)
return RoomMemberMasterHandler(self)
Expand Down