0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

ircd:Ⓜ️:fed: Generate POST /publicRooms content by default; add console search param.

This commit is contained in:
Jason Volk 2020-05-29 01:23:19 -07:00
parent 9457b1d34b
commit 761ff66464
3 changed files with 80 additions and 16 deletions

View file

@ -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;
};

View file

@ -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)

View file

@ -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<mutable_buffer> buf
{
16_KiB
@ -14185,14 +14191,14 @@ console_cmd__fed__public_rooms(opt &out, const string_view &line)
response.get<size_t>("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)