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

ircd:Ⓜ️:v1: Add the user::keys::claim ctor stack complex; minor cleanup.

This commit is contained in:
Jason Volk 2019-02-07 21:40:32 -08:00
parent dcb1f2197e
commit fb6be95f2c
2 changed files with 127 additions and 1 deletions

View file

@ -59,6 +59,9 @@ struct ircd::m::v1::user::keys::claim
:server::request
{
using opts = v1::user::opts;
using device = std::pair<string_view, string_view>;
using devices = vector_view<const device>;
using user_devices = std::pair<m::user::id, devices>;
explicit operator json::object() const
{
@ -71,5 +74,24 @@ struct ircd::m::v1::user::keys::claim
const mutable_buffer &,
opts);
claim(const vector_view<const user_devices> &,
const mutable_buffer &,
opts);
claim(const user_devices &,
const mutable_buffer &,
opts);
claim(const m::user::id &,
const device &device,
const mutable_buffer &,
opts);
claim(const m::user::id &,
const string_view &device_id,
const string_view &algorithm,
const mutable_buffer &,
opts);
claim() = default;
};

View file

@ -774,6 +774,10 @@ ircd::m::v1::make_join::make_join(const room::id &room_id,
// v1/user_keys.h
//
//
// query
//
ircd::m::v1::user::keys::query::query(const m::user::id &user_id,
const mutable_buffer &buf,
opts opts)
@ -846,9 +850,14 @@ ircd::m::v1::user::keys::query::query(const vector_view<const user_devices> &v,
}
}
const json::object &content
{
out.completed()
};
new (this) query
{
json::object(out.completed()), buf + size(out.completed()), std::move(opts)
content, buf + size(string_view(content)), std::move(opts)
};
}
@ -893,6 +902,101 @@ ircd::m::v1::user::keys::query::query(const json::object &content,
{
}
//
// claim
//
ircd::m::v1::user::keys::claim::claim(const m::user::id &user_id,
const string_view &device_id,
const string_view &algorithm,
const mutable_buffer &buf,
opts opts)
:claim
{
user_id,
device
{
device_id, algorithm
},
buf,
std::move(opts)
}
{
}
ircd::m::v1::user::keys::claim::claim(const m::user::id &user_id,
const device &device,
const mutable_buffer &buf,
opts opts)
:claim
{
user_devices
{
user_id, { &device, 1 }
},
buf,
std::move(opts)
}
{
}
ircd::m::v1::user::keys::claim::claim(const user_devices &ud,
const mutable_buffer &buf,
opts opts)
:claim
{
vector_view<const user_devices>
{
&ud, 1
},
buf,
std::move(opts)
}
{
}
ircd::m::v1::user::keys::claim::claim(const vector_view<const user_devices> &v,
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 &ud : v)
{
json::stack::object user
{
one_time_keys, ud.first
};
for(const auto &device : ud.second)
{
const auto &device_id(device.first);
const auto &algorithm_name(device.second);
json::stack::member
{
user, device_id, algorithm_name
};
}
}
}
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,
const mutable_buffer &buf,
opts opts)