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

Commit a7a3743

Browse files
Integrate knock rooms with the public rooms directory (#9359)
This PR implements the ["Changes regarding the Public Rooms Directory"](https://github.com/Sorunome/matrix-doc/blob/soru/knock/proposals/2403-knock.md#changes-regarding-the-public-rooms-directory) section of knocking MSC2403. Specifically, it: * Allows rooms with `join_rule` "knock" to be returned by the query behind the public rooms directory * Adds the field `join_rule` to each room entry returned by a public rooms directory query, so clients can know whether to attempt a join or knock on a room Based on #6739. Complement tests for this change: matrix-org/complement#72
1 parent d936371 commit a7a3743

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

changelog.d/9359.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by Sorunome and anoa.

synapse/handlers/room_list.py

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def build_room_entry(room):
169169
"world_readable": room["history_visibility"]
170170
== HistoryVisibility.WORLD_READABLE,
171171
"guest_can_join": room["guest_access"] == "can_join",
172+
"join_rule": room["join_rules"],
172173
}
173174

174175
# Filter out Nones – rather omit the field altogether

synapse/storage/databases/main/room.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from enum import Enum
2020
from typing import Any, Dict, List, Optional, Tuple
2121

22-
from synapse.api.constants import EventTypes
22+
from synapse.api.constants import EventTypes, JoinRules
2323
from synapse.api.errors import StoreError
2424
from synapse.api.room_versions import RoomVersion, RoomVersions
2525
from synapse.storage._base import SQLBaseStore, db_to_json
@@ -177,11 +177,13 @@ def _count_public_rooms_txn(txn):
177177
INNER JOIN room_stats_current USING (room_id)
178178
WHERE
179179
(
180-
join_rules = 'public' OR history_visibility = 'world_readable'
180+
join_rules = 'public' OR join_rules = '%(knock_join_rule)s'
181+
OR history_visibility = 'world_readable'
181182
)
182183
AND joined_members > 0
183184
""" % {
184-
"published_sql": published_sql
185+
"published_sql": published_sql,
186+
"knock_join_rule": JoinRules.KNOCK,
185187
}
186188

187189
txn.execute(sql, query_args)
@@ -303,15 +305,16 @@ async def get_largest_public_rooms(
303305
sql = """
304306
SELECT
305307
room_id, name, topic, canonical_alias, joined_members,
306-
avatar, history_visibility, joined_members, guest_access
308+
avatar, history_visibility, guest_access, join_rules
307309
FROM (
308310
%(published_sql)s
309311
) published
310312
INNER JOIN room_stats_state USING (room_id)
311313
INNER JOIN room_stats_current USING (room_id)
312314
WHERE
313315
(
314-
join_rules = 'public' OR history_visibility = 'world_readable'
316+
join_rules = 'public' OR join_rules = '%(knock_join_rule)s'
317+
OR history_visibility = 'world_readable'
315318
)
316319
AND joined_members > 0
317320
%(where_clause)s
@@ -320,6 +323,7 @@ async def get_largest_public_rooms(
320323
"published_sql": published_sql,
321324
"where_clause": where_clause,
322325
"dir": "DESC" if forwards else "ASC",
326+
"knock_join_rule": JoinRules.KNOCK,
323327
}
324328

325329
if limit is not None:

0 commit comments

Comments
 (0)