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

Integrate knock rooms with the public rooms directory #9359

Merged
merged 3 commits into from
Jun 9, 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/9359.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by Sorunome and anoa.
1 change: 1 addition & 0 deletions synapse/handlers/room_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def build_room_entry(room):
"world_readable": room["history_visibility"]
== HistoryVisibility.WORLD_READABLE,
"guest_can_join": room["guest_access"] == "can_join",
"join_rule": room["join_rules"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we OK to just always include this? I don't really see a problem with it, just wanted to make sure. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine. It's in the latest, unreleased spec as a field for all rooms (knocking or not), and should be backwards-compatible with clients that aren't aware of this field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was what I figured too, just wanted to hear the reasoning. :)

}

# Filter out Nones – rather omit the field altogether
Expand Down
14 changes: 9 additions & 5 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple

from synapse.api.constants import EventTypes
from synapse.api.constants import EventTypes, JoinRules
from synapse.api.errors import StoreError
from synapse.api.room_versions import RoomVersion, RoomVersions
from synapse.storage._base import SQLBaseStore, db_to_json
Expand Down Expand Up @@ -177,11 +177,13 @@ def _count_public_rooms_txn(txn):
INNER JOIN room_stats_current USING (room_id)
WHERE
(
join_rules = 'public' OR history_visibility = 'world_readable'
join_rules = 'public' OR join_rules = '%(knock_join_rule)s'
OR history_visibility = 'world_readable'
)
AND joined_members > 0
""" % {
"published_sql": published_sql
"published_sql": published_sql,
"knock_join_rule": JoinRules.KNOCK,
}

txn.execute(sql, query_args)
Expand Down Expand Up @@ -303,15 +305,16 @@ async def get_largest_public_rooms(
sql = """
SELECT
room_id, name, topic, canonical_alias, joined_members,
avatar, history_visibility, joined_members, guest_access
avatar, history_visibility, guest_access, join_rules
FROM (
%(published_sql)s
) published
INNER JOIN room_stats_state USING (room_id)
INNER JOIN room_stats_current USING (room_id)
WHERE
(
join_rules = 'public' OR history_visibility = 'world_readable'
join_rules = 'public' OR join_rules = '%(knock_join_rule)s'
OR history_visibility = 'world_readable'
)
AND joined_members > 0
%(where_clause)s
Expand All @@ -320,6 +323,7 @@ async def get_largest_public_rooms(
"published_sql": published_sql,
"where_clause": where_clause,
"dir": "DESC" if forwards else "ASC",
"knock_join_rule": JoinRules.KNOCK,
}

if limit is not None:
Expand Down