From 238cc104890e1ca5727f0d050f3f46fbe69f602b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 21 Apr 2023 21:20:53 -0700 Subject: [PATCH] ircd::m::rooms: Implement matrix-org/matrix-spec-proposals#3827 --- include/ircd/m/rooms.h | 3 +++ matrix/rooms.cc | 4 ++++ modules/client/publicrooms.cc | 1 + modules/client/versions.cc | 9 +++++++++ modules/federation/publicrooms.cc | 1 + 5 files changed, 18 insertions(+) diff --git a/include/ircd/m/rooms.h b/include/ircd/m/rooms.h index 657e7bb2d..42d9d7631 100644 --- a/include/ircd/m/rooms.h +++ b/include/ircd/m/rooms.h @@ -48,6 +48,9 @@ struct ircd::m::rooms::opts /// Room alias prefix search string_view room_alias; + /// Room type search + string_view room_type; + /// user::rooms convenience id::user user_id; diff --git a/matrix/rooms.cc b/matrix/rooms.cc index abacf254d..a13f2e051 100644 --- a/matrix/rooms.cc +++ b/matrix/rooms.cc @@ -138,6 +138,10 @@ ircd::m::rooms::for_each(const opts &opts, if(!join_rule(room, opts.join_rule)) return; + if(opts.room_type) + if(!m::type(room_id, opts.room_type)) + return; + if(opts.server && opts.request_node_id && my_host(opts.server)) if(!room::aliases(room_id).has_server(opts.server)) return; diff --git a/modules/client/publicrooms.cc b/modules/client/publicrooms.cc index e45f2e4d7..e8e2ccc61 100644 --- a/modules/client/publicrooms.cc +++ b/modules/client/publicrooms.cc @@ -134,6 +134,7 @@ get__publicrooms(client &client, opts.lower_bound = true; opts.room_id = since; opts.request_user_id = request.user_id; + opts.room_type = json::string{filter["room_type"]}; if(m::valid(m::id::USER, search_term)) opts.user_id = search_term; diff --git a/modules/client/versions.cc b/modules/client/versions.cc index f79d5428d..d5cbe4b76 100644 --- a/modules/client/versions.cc +++ b/modules/client/versions.cc @@ -241,4 +241,13 @@ ircd::m::client_versions::append_unstable_features(client &client, bool(e2ee_forced_trusted_private) } }; + + // Supports filtering of /publicRooms by room type as per MSC3827 + json::stack::member + { + out, "org.matrix.msc3827.stable", json::value + { + true + } + }; } diff --git a/modules/federation/publicrooms.cc b/modules/federation/publicrooms.cc index c5e065cac..0e596ce2d 100644 --- a/modules/federation/publicrooms.cc +++ b/modules/federation/publicrooms.cc @@ -114,6 +114,7 @@ handle_get(client &client, opts.room_id = since; opts.search_term = search_term; opts.request_node_id = request.node_id; + opts.room_type = json::string(filter["room_type"]); size_t count{0}; m::room::id::buf prev_batch_buf;