0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 07:20:55 +01:00

modules/client/versions: Generate response content dynamically.

This commit is contained in:
Jason Volk 2019-07-06 17:58:47 -07:00
parent 17925b2bd9
commit f9dbd306d6

View file

@ -8,16 +8,26 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
using namespace ircd;
namespace ircd::m::client_versions
{
static void append_unstable_features(client &, resource::request &, json::stack &);
static void append_versions(client &, resource::request &, json::stack &);
static resource::response get(client &, resource::request &);
mapi::header
extern conf::item<bool> m_lazy_load_members;
extern conf::item<std::string> versions;
extern resource::method method_get;
extern resource resource;
}
ircd::mapi::header
IRCD_MODULE
{
"Client 2.1 :Versions"
};
resource
versions_resource
decltype(ircd::m::client_versions::resource)
ircd::m::client_versions::resource
{
"/_matrix/client/versions",
{
@ -25,23 +35,88 @@ versions_resource
}
};
resource::response
get_versions(client &client,
decltype(ircd::m::client_versions::method_get)
ircd::m::client_versions::method_get
{
resource, "GET", get
};
ircd::resource::response
ircd::m::client_versions::get(client &client,
resource::request &request)
{
static const json::object object
char buf[512];
json::stack out{buf};
{
R"({"versions":["r0.3.0","r0.4.0","r0.5.0"]})"
};
json::stack::object top{out};
append_versions(client, request, out);
append_unstable_features(client, request, out);
}
return resource::response
{
client, object
client, json::object
{
out.completed()
}
};
}
resource::method
getter
/// Note this conf item doesn't persist to and from the database, which means
/// it assumes its default value on every startup.
decltype(ircd::m::client_versions::versions)
ircd::m::client_versions::versions
{
versions_resource, "GET", get_versions
{ "name", "ircd.m.client.versions.versions" },
{ "default", "r0.3.0 r0.4.0 r0.5.0" },
{ "persist", false },
};
void
ircd::m::client_versions::append_versions(client &client,
resource::request &request,
json::stack &out)
{
json::stack::array array
{
out, "versions"
};
const string_view &list
{
versions
};
tokens(list, ' ', [&array]
(const string_view &version)
{
array.append(version);
});
}
decltype(ircd::m::client_versions::m_lazy_load_members)
ircd::m::client_versions::m_lazy_load_members
{
{ "name", "ircd.m.client.versions.m_lazy_load_members" },
{ "default", true, },
};
void
ircd::m::client_versions::append_unstable_features(client &client,
resource::request &request,
json::stack &out)
{
json::stack::object object
{
out, "unstable_features"
};
// m.lazy_load_members
json::stack::member
{
out, "m.lazy_load_members", json::value
{
bool(m_lazy_load_members)
}
};
}