mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Remove unused room_alias
field from /createRoom
response (#15093)
* Change `create_room` return type * Don't return room alias from /createRoom * Update other callsites * Fix up mypy complaints It looks like new_room_user_id is None iff new_room_id is None. It's a shame we haven't expressed this in a way that mypy can understand. * Changelog
This commit is contained in:
parent
8219525b66
commit
647ff3ef65
1
changelog.d/15093.bugfix
Normal file
1
changelog.d/15093.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Remove the unspecced `room_alias` field from the [`/createRoom`](https://spec.matrix.org/v1.6/client-server-api/#post_matrixclientv3createroom) response.
|
@ -476,7 +476,7 @@ class RegistrationHandler:
|
|||||||
# create room expects the localpart of the room alias
|
# create room expects the localpart of the room alias
|
||||||
config["room_alias_name"] = room_alias.localpart
|
config["room_alias_name"] = room_alias.localpart
|
||||||
|
|
||||||
info, _ = await room_creation_handler.create_room(
|
room_id, _, _ = await room_creation_handler.create_room(
|
||||||
fake_requester,
|
fake_requester,
|
||||||
config=config,
|
config=config,
|
||||||
ratelimit=False,
|
ratelimit=False,
|
||||||
@ -490,7 +490,7 @@ class RegistrationHandler:
|
|||||||
user_id, authenticated_entity=self._server_name
|
user_id, authenticated_entity=self._server_name
|
||||||
),
|
),
|
||||||
target=UserID.from_string(user_id),
|
target=UserID.from_string(user_id),
|
||||||
room_id=info["room_id"],
|
room_id=room_id,
|
||||||
# Since it was just created, there are no remote hosts.
|
# Since it was just created, there are no remote hosts.
|
||||||
remote_room_hosts=[],
|
remote_room_hosts=[],
|
||||||
action="join",
|
action="join",
|
||||||
|
@ -690,13 +690,14 @@ class RoomCreationHandler:
|
|||||||
config: JsonDict,
|
config: JsonDict,
|
||||||
ratelimit: bool = True,
|
ratelimit: bool = True,
|
||||||
creator_join_profile: Optional[JsonDict] = None,
|
creator_join_profile: Optional[JsonDict] = None,
|
||||||
) -> Tuple[dict, int]:
|
) -> Tuple[str, Optional[RoomAlias], int]:
|
||||||
"""Creates a new room.
|
"""Creates a new room.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
requester:
|
requester: The user who requested the room creation.
|
||||||
The user who requested the room creation.
|
config: A dict of configuration options. This will be the body of
|
||||||
config : A dict of configuration options.
|
a /createRoom request; see
|
||||||
|
https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3createroom
|
||||||
ratelimit: set to False to disable the rate limiter
|
ratelimit: set to False to disable the rate limiter
|
||||||
|
|
||||||
creator_join_profile:
|
creator_join_profile:
|
||||||
@ -707,14 +708,17 @@ class RoomCreationHandler:
|
|||||||
`avatar_url` and/or `displayname`.
|
`avatar_url` and/or `displayname`.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
First, a dict containing the keys `room_id` and, if an alias
|
A 3-tuple containing:
|
||||||
was, requested, `room_alias`. Secondly, the stream_id of the
|
- the room ID;
|
||||||
last persisted event.
|
- if requested, the room alias, otherwise None; and
|
||||||
|
- the `stream_id` of the last persisted event.
|
||||||
Raises:
|
Raises:
|
||||||
SynapseError if the room ID couldn't be stored, 3pid invitation config
|
SynapseError:
|
||||||
validation failed, or something went horribly wrong.
|
if the room ID couldn't be stored, 3pid invitation config
|
||||||
ResourceLimitError if server is blocked to some resource being
|
validation failed, or something went horribly wrong.
|
||||||
exceeded
|
ResourceLimitError:
|
||||||
|
if server is blocked to some resource being
|
||||||
|
exceeded
|
||||||
"""
|
"""
|
||||||
user_id = requester.user.to_string()
|
user_id = requester.user.to_string()
|
||||||
|
|
||||||
@ -1024,11 +1028,6 @@ class RoomCreationHandler:
|
|||||||
last_sent_event_id = member_event_id
|
last_sent_event_id = member_event_id
|
||||||
depth += 1
|
depth += 1
|
||||||
|
|
||||||
result = {"room_id": room_id}
|
|
||||||
|
|
||||||
if room_alias:
|
|
||||||
result["room_alias"] = room_alias.to_string()
|
|
||||||
|
|
||||||
# Always wait for room creation to propagate before returning
|
# Always wait for room creation to propagate before returning
|
||||||
await self._replication.wait_for_stream_position(
|
await self._replication.wait_for_stream_position(
|
||||||
self.hs.config.worker.events_shard_config.get_instance(room_id),
|
self.hs.config.worker.events_shard_config.get_instance(room_id),
|
||||||
@ -1036,7 +1035,7 @@ class RoomCreationHandler:
|
|||||||
last_stream_id,
|
last_stream_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
return result, last_stream_id
|
return room_id, room_alias, last_stream_id
|
||||||
|
|
||||||
async def _send_events_for_new_room(
|
async def _send_events_for_new_room(
|
||||||
self,
|
self,
|
||||||
@ -1825,7 +1824,7 @@ class RoomShutdownHandler:
|
|||||||
new_room_user_id, authenticated_entity=requester_user_id
|
new_room_user_id, authenticated_entity=requester_user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
info, stream_id = await self._room_creation_handler.create_room(
|
new_room_id, _, stream_id = await self._room_creation_handler.create_room(
|
||||||
room_creator_requester,
|
room_creator_requester,
|
||||||
config={
|
config={
|
||||||
"preset": RoomCreationPreset.PUBLIC_CHAT,
|
"preset": RoomCreationPreset.PUBLIC_CHAT,
|
||||||
@ -1834,7 +1833,6 @@ class RoomShutdownHandler:
|
|||||||
},
|
},
|
||||||
ratelimit=False,
|
ratelimit=False,
|
||||||
)
|
)
|
||||||
new_room_id = info["room_id"]
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Shutting down room %r, joining to new room: %r", room_id, new_room_id
|
"Shutting down room %r, joining to new room: %r", room_id, new_room_id
|
||||||
@ -1887,6 +1885,7 @@ class RoomShutdownHandler:
|
|||||||
|
|
||||||
# Join users to new room
|
# Join users to new room
|
||||||
if new_room_user_id:
|
if new_room_user_id:
|
||||||
|
assert new_room_id is not None
|
||||||
await self.room_member_handler.update_membership(
|
await self.room_member_handler.update_membership(
|
||||||
requester=target_requester,
|
requester=target_requester,
|
||||||
target=target_requester.user,
|
target=target_requester.user,
|
||||||
@ -1919,6 +1918,7 @@ class RoomShutdownHandler:
|
|||||||
|
|
||||||
aliases_for_room = await self.store.get_aliases_for_room(room_id)
|
aliases_for_room = await self.store.get_aliases_for_room(room_id)
|
||||||
|
|
||||||
|
assert new_room_id is not None
|
||||||
await self.store.update_aliases_for_room(
|
await self.store.update_aliases_for_room(
|
||||||
room_id, new_room_id, requester_user_id
|
room_id, new_room_id, requester_user_id
|
||||||
)
|
)
|
||||||
|
@ -1576,14 +1576,14 @@ class ModuleApi:
|
|||||||
)
|
)
|
||||||
|
|
||||||
requester = create_requester(user_id)
|
requester = create_requester(user_id)
|
||||||
room_id_and_alias, _ = await self._hs.get_room_creation_handler().create_room(
|
room_id, room_alias, _ = await self._hs.get_room_creation_handler().create_room(
|
||||||
requester=requester,
|
requester=requester,
|
||||||
config=config,
|
config=config,
|
||||||
ratelimit=ratelimit,
|
ratelimit=ratelimit,
|
||||||
creator_join_profile=creator_join_profile,
|
creator_join_profile=creator_join_profile,
|
||||||
)
|
)
|
||||||
|
room_alias_str = room_alias.to_string() if room_alias else None
|
||||||
return room_id_and_alias["room_id"], room_id_and_alias.get("room_alias", None)
|
return room_id, room_alias_str
|
||||||
|
|
||||||
async def set_displayname(
|
async def set_displayname(
|
||||||
self,
|
self,
|
||||||
|
@ -160,11 +160,11 @@ class RoomCreateRestServlet(TransactionRestServlet):
|
|||||||
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
||||||
requester = await self.auth.get_user_by_req(request)
|
requester = await self.auth.get_user_by_req(request)
|
||||||
|
|
||||||
info, _ = await self._room_creation_handler.create_room(
|
room_id, _, _ = await self._room_creation_handler.create_room(
|
||||||
requester, self.get_room_config(request)
|
requester, self.get_room_config(request)
|
||||||
)
|
)
|
||||||
|
|
||||||
return 200, info
|
return 200, {"room_id": room_id}
|
||||||
|
|
||||||
def get_room_config(self, request: Request) -> JsonDict:
|
def get_room_config(self, request: Request) -> JsonDict:
|
||||||
user_supplied_config = parse_json_object_from_request(request)
|
user_supplied_config = parse_json_object_from_request(request)
|
||||||
|
@ -178,7 +178,7 @@ class ServerNoticesManager:
|
|||||||
"avatar_url": self._config.servernotices.server_notices_mxid_avatar_url,
|
"avatar_url": self._config.servernotices.server_notices_mxid_avatar_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
info, _ = await self._room_creation_handler.create_room(
|
room_id, _, _ = await self._room_creation_handler.create_room(
|
||||||
requester,
|
requester,
|
||||||
config={
|
config={
|
||||||
"preset": RoomCreationPreset.PRIVATE_CHAT,
|
"preset": RoomCreationPreset.PRIVATE_CHAT,
|
||||||
@ -188,7 +188,6 @@ class ServerNoticesManager:
|
|||||||
ratelimit=False,
|
ratelimit=False,
|
||||||
creator_join_profile=join_profile,
|
creator_join_profile=join_profile,
|
||||||
)
|
)
|
||||||
room_id = info["room_id"]
|
|
||||||
|
|
||||||
self.maybe_get_notice_room_for_user.invalidate((user_id,))
|
self.maybe_get_notice_room_for_user.invalidate((user_id,))
|
||||||
|
|
||||||
|
@ -43,8 +43,9 @@ class CleanupExtremBackgroundUpdateStoreTestCase(HomeserverTestCase):
|
|||||||
# Create a test user and room
|
# Create a test user and room
|
||||||
self.user = UserID("alice", "test")
|
self.user = UserID("alice", "test")
|
||||||
self.requester = create_requester(self.user)
|
self.requester = create_requester(self.user)
|
||||||
info, _ = self.get_success(self.room_creator.create_room(self.requester, {}))
|
self.room_id, _, _ = self.get_success(
|
||||||
self.room_id = info["room_id"]
|
self.room_creator.create_room(self.requester, {})
|
||||||
|
)
|
||||||
|
|
||||||
def run_background_update(self) -> None:
|
def run_background_update(self) -> None:
|
||||||
"""Re run the background update to clean up the extremities."""
|
"""Re run the background update to clean up the extremities."""
|
||||||
@ -275,10 +276,9 @@ class CleanupExtremDummyEventsTestCase(HomeserverTestCase):
|
|||||||
self.user = UserID.from_string(self.register_user("user1", "password"))
|
self.user = UserID.from_string(self.register_user("user1", "password"))
|
||||||
self.token1 = self.login("user1", "password")
|
self.token1 = self.login("user1", "password")
|
||||||
self.requester = create_requester(self.user)
|
self.requester = create_requester(self.user)
|
||||||
info, _ = self.get_success(
|
self.room_id, _, _ = self.get_success(
|
||||||
self.room_creator.create_room(self.requester, {"visibility": "public"})
|
self.room_creator.create_room(self.requester, {"visibility": "public"})
|
||||||
)
|
)
|
||||||
self.room_id = info["room_id"]
|
|
||||||
self.event_creator = homeserver.get_event_creation_handler()
|
self.event_creator = homeserver.get_event_creation_handler()
|
||||||
homeserver.config.consent.user_consent_version = self.CONSENT_VERSION
|
homeserver.config.consent.user_consent_version = self.CONSENT_VERSION
|
||||||
|
|
||||||
|
@ -33,8 +33,7 @@ class ExtremStatisticsTestCase(HomeserverTestCase):
|
|||||||
events = [(3, 2), (6, 2), (4, 6)]
|
events = [(3, 2), (6, 2), (4, 6)]
|
||||||
|
|
||||||
for event_count, extrems in events:
|
for event_count, extrems in events:
|
||||||
info, _ = self.get_success(room_creator.create_room(requester, {}))
|
room_id, _, _ = self.get_success(room_creator.create_room(requester, {}))
|
||||||
room_id = info["room_id"]
|
|
||||||
|
|
||||||
last_event = None
|
last_event = None
|
||||||
|
|
||||||
|
@ -50,12 +50,14 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||||||
self.otherRequester = create_requester(self.otherUser)
|
self.otherRequester = create_requester(self.otherUser)
|
||||||
|
|
||||||
# Create a test room
|
# Create a test room
|
||||||
info, _ = self.get_success(self.room_creator.create_room(self.ourRequester, {}))
|
self.room_id1, _, _ = self.get_success(
|
||||||
self.room_id1 = info["room_id"]
|
self.room_creator.create_room(self.ourRequester, {})
|
||||||
|
)
|
||||||
|
|
||||||
# Create a second test room
|
# Create a second test room
|
||||||
info, _ = self.get_success(self.room_creator.create_room(self.ourRequester, {}))
|
self.room_id2, _, _ = self.get_success(
|
||||||
self.room_id2 = info["room_id"]
|
self.room_creator.create_room(self.ourRequester, {})
|
||||||
|
)
|
||||||
|
|
||||||
# Join the second user to the first room
|
# Join the second user to the first room
|
||||||
memberEvent, memberEventContext = self.get_success(
|
memberEvent, memberEventContext = self.get_success(
|
||||||
|
@ -47,7 +47,7 @@ class MessageAcceptTests(unittest.HomeserverTestCase):
|
|||||||
room_creator.create_room(
|
room_creator.create_room(
|
||||||
our_user, room_creator._presets_dict["public_chat"], ratelimit=False
|
our_user, room_creator._presets_dict["public_chat"], ratelimit=False
|
||||||
)
|
)
|
||||||
)[0]["room_id"]
|
)[0]
|
||||||
|
|
||||||
self.store = self.hs.get_datastores().main
|
self.store = self.hs.get_datastores().main
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user