mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
ircd:Ⓜ️:device: Reduce/reuse codepath to set property to value.
This commit is contained in:
parent
9ac34573e5
commit
135798c8ab
1 changed files with 2 additions and 12 deletions
|
@ -50,28 +50,18 @@ bool
|
||||||
ircd::m::device::set(const m::user &user,
|
ircd::m::device::set(const m::user &user,
|
||||||
const device &device)
|
const device &device)
|
||||||
{
|
{
|
||||||
const user::room user_room{user};
|
|
||||||
const string_view &device_id
|
const string_view &device_id
|
||||||
{
|
{
|
||||||
json::at<"device_id"_>(device)
|
json::at<"device_id"_>(device)
|
||||||
};
|
};
|
||||||
|
|
||||||
json::for_each(device, [&user, &user_room, &device_id]
|
json::for_each(device, [&user, &device_id]
|
||||||
(const auto &prop, auto &&val)
|
(const auto &prop, auto &&val)
|
||||||
{
|
{
|
||||||
if(!json::defined(json::value(val)))
|
if(!json::defined(json::value(val)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char buf[m::event::TYPE_MAX_SIZE];
|
set(user, device_id, prop, val);
|
||||||
const string_view type{fmt::sprintf
|
|
||||||
{
|
|
||||||
buf, "ircd.device.%s", prop
|
|
||||||
}};
|
|
||||||
|
|
||||||
m::send(user_room, user, type, device_id, json::members
|
|
||||||
{
|
|
||||||
{ "", val }
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue