0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 00:10:59 +01:00

ircd:Ⓜ️:v1::user::keys::claim: Add additional convenience construction.

This commit is contained in:
Jason Volk 2019-02-21 16:46:23 -08:00
parent 7c69752114
commit 6ccc171bce
2 changed files with 39 additions and 0 deletions

View file

@ -67,6 +67,7 @@ struct ircd::m::v1::user::keys::claim
using device = std::pair<string_view, string_view>; using device = std::pair<string_view, string_view>;
using devices = vector_view<const device>; using devices = vector_view<const device>;
using user_devices = std::pair<m::user::id, devices>; using user_devices = std::pair<m::user::id, devices>;
using user_devices_map = std::map<m::user::id, json::object>;
explicit operator json::object() const explicit operator json::object() const
{ {
@ -79,6 +80,10 @@ struct ircd::m::v1::user::keys::claim
const mutable_buffer &, const mutable_buffer &,
opts); opts);
claim(const user_devices_map &,
const mutable_buffer &,
opts);
claim(const vector_view<const user_devices> &, claim(const vector_view<const user_devices> &,
const mutable_buffer &, const mutable_buffer &,
opts); opts);

View file

@ -1087,6 +1087,40 @@ ircd::m::v1::user::keys::claim::claim(const vector_view<const user_devices> &v,
}; };
} }
ircd::m::v1::user::keys::claim::claim(const user_devices_map &map,
const mutable_buffer &buf,
opts opts)
{
json::stack out{buf};
{
json::stack::object top{out};
json::stack::object one_time_keys
{
top, "one_time_keys"
};
for(const auto &p : map)
{
const m::user::id &user_id(p.first);
const json::object &devices(p.second);
json::stack::member user
{
one_time_keys, user_id, devices
};
}
}
const json::object &content
{
out.completed()
};
new (this) claim
{
content, buf + size(string_view(content)), std::move(opts)
};
}
ircd::m::v1::user::keys::claim::claim(const json::object &content, ircd::m::v1::user::keys::claim::claim(const json::object &content,
const mutable_buffer &buf, const mutable_buffer &buf,
opts opts) opts opts)