diff --git a/include/ircd/m/fed/public_rooms.h b/include/ircd/m/fed/public_rooms.h index 24c75225d..20787d08b 100644 --- a/include/ircd/m/fed/public_rooms.h +++ b/include/ircd/m/fed/public_rooms.h @@ -43,4 +43,5 @@ struct ircd::m::fed::public_rooms::opts string_view since; string_view third_party_instance_id; bool include_all_networks {true}; + string_view search_term; }; diff --git a/matrix/fed.cc b/matrix/fed.cc index 55dd0ae2a..d7b8e53e5 100644 --- a/matrix/fed.cc +++ b/matrix/fed.cc @@ -185,7 +185,7 @@ ircd::m::fed::public_rooms::public_rooms(const string_view &remote, opts.remote = remote; if(likely(!defined(json::get<"method"_>(opts.request)))) - json::get<"method"_>(opts.request) = "GET"; + json::get<"method"_>(opts.request) = "POST"; mutable_buffer buf{buf_}; if(likely(!defined(json::get<"uri"_>(opts.request)))) @@ -194,25 +194,82 @@ ircd::m::fed::public_rooms::public_rooms(const string_view &remote, std::stringstream qss; pubsetbuf(qss, query); - if(opts.since) - qss << "&since=" - << url::encode(since, opts.since); + if(json::get<"method"_>(opts.request) == "GET") + { + if(opts.since) + qss << "&since=" + << url::encode(since, opts.since); - if(opts.third_party_instance_id) - qss << "&third_party_instance_id=" - << url::encode(tpid, opts.third_party_instance_id); + if(opts.third_party_instance_id) + qss << "&third_party_instance_id=" + << url::encode(tpid, opts.third_party_instance_id); + } json::get<"uri"_>(opts.request) = fmt::sprintf { buf, "/_matrix/federation/v1/publicRooms?limit=%zu%s%s", opts.limit, - opts.include_all_networks? "&include_all_networks=true" : "", + opts.include_all_networks? + "&include_all_networks=true"_sv: + string_view{}, view(qss, query) }; consume(buf, size(json::get<"uri"_>(opts.request))); } + if(likely(!defined(json::get<"content"_>(opts.request)))) + { + json::stack out{buf}; + json::stack::object top{out}; + if(likely(json::get<"method"_>(opts.request) == "POST")) + { + if(opts.limit) + json::stack::member + { + top, "limit", json::value + { + long(opts.limit) + } + }; + + if(opts.include_all_networks) + json::stack::member + { + top, "include_all_networks", json::value + { + opts.include_all_networks + } + }; + + if(opts.third_party_instance_id) + json::stack::member + { + top, "third_party_instance_id", json::value + { + opts.third_party_instance_id + } + }; + + if(opts.search_term) + { + json::stack::object filter + { + top, "filter" + }; + + json::stack::member + { + filter, "generic_search_term", opts.search_term + }; + } + } + + top.~object(); + json::get<"content"_>(opts.request) = out.completed(); + consume(buf, size(string_view(json::get<"content"_>(opts.request)))); + } + return request { buf, std::move(opts) diff --git a/modules/console.cc b/modules/console.cc index c18aa8a43..11721bc46 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -14135,33 +14135,39 @@ console_cmd__fed__public_rooms(opt &out, const string_view &line) { const params param{line, " ", { - "remote", "limit", "all_networks", "3pid" + "remote", "limit", "search_term", "all_networks", "tpid" }}; const string_view remote { - param.at(0) + param.at("remote") }; const auto limit { - param.at(1, 32) + param.at("limit", 32) + }; + + const auto search_term + { + param["search_term"] }; const auto all_nets { - param.at(2, false) + param.at("all_networks", false) }; const auto tpid { - param[3] + param["tpid"] }; m::fed::public_rooms::opts opts; opts.limit = limit; opts.third_party_instance_id = tpid; opts.include_all_networks = all_nets; + opts.search_term = search_term; const unique_buffer buf { 16_KiB @@ -14185,14 +14191,14 @@ console_cmd__fed__public_rooms(opt &out, const string_view &line) response.get("total_room_count_estimate") }; - const auto next_batch + const json::string next_batch { - unquote(response.get("next_batch")) + response["next_batch"] }; const json::array &rooms { - response.get("chunk") + response["chunk"] }; for(const json::object &summary : rooms)