mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 08:42:34 +01:00
ircd:Ⓜ️:device: Add set overload for device_list_update structure.
This commit is contained in:
parent
9bca61313e
commit
27aea89183
2 changed files with 39 additions and 0 deletions
|
@ -135,6 +135,7 @@ struct ircd::m::device
|
|||
static bool put(const user &, const string_view &id, const string_view &prop, const string_view &val);
|
||||
static bool set(const user &, const string_view &id, const string_view &prop, const string_view &val);
|
||||
static bool set(const user &, const device &);
|
||||
static bool set(const device_list_update &);
|
||||
|
||||
// composite interface
|
||||
static std::map<std::string, long> count_one_time_keys(const user &, const string_view &);
|
||||
|
|
|
@ -46,6 +46,44 @@ ircd::m::device::count_one_time_keys(const user &user,
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::device::set(const device_list_update &update)
|
||||
{
|
||||
const m::user &user
|
||||
{
|
||||
json::at<"user_id"_>(update)
|
||||
};
|
||||
|
||||
const auto &device_id
|
||||
{
|
||||
json::at<"device_id"_>(update)
|
||||
};
|
||||
|
||||
if(json::get<"deleted"_>(update))
|
||||
return del(user, device_id);
|
||||
|
||||
// Properties we're interested in for now...
|
||||
static const string_view mask[]
|
||||
{
|
||||
"device_id",
|
||||
"device_display_name",
|
||||
"keys",
|
||||
};
|
||||
|
||||
bool ret {false};
|
||||
json::for_each(update, mask, [&ret, &user, &device_id]
|
||||
(const auto &prop, auto &&val)
|
||||
{
|
||||
if constexpr(std::is_assignable<string_view, decltype(val)>())
|
||||
{
|
||||
if(json::defined(json::value(val)))
|
||||
ret |= set(user, device_id, prop, val);
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::device::set(const m::user &user,
|
||||
const device &device)
|
||||
|
|
Loading…
Reference in a new issue