mirror of
https://github.com/matrix-construct/construct
synced 2024-05-15 17:33:46 +02:00
modules/console: Add wildcard for all devices to user devices update cmd.
This commit is contained in:
parent
faf796a56b
commit
b4b26484ec
|
@ -14457,9 +14457,9 @@ console_cmd__user__devices__update(opt &out, const string_view &line)
|
||||||
param.at("user_id")
|
param.at("user_id")
|
||||||
};
|
};
|
||||||
|
|
||||||
const string_view &device_id
|
const string_view &device_id_
|
||||||
{
|
{
|
||||||
param.at("device_id")
|
param.at("device_id", "*"_sv)
|
||||||
};
|
};
|
||||||
|
|
||||||
const bool deleted
|
const bool deleted
|
||||||
|
@ -14472,20 +14472,46 @@ console_cmd__user__devices__update(opt &out, const string_view &line)
|
||||||
user_id
|
user_id
|
||||||
};
|
};
|
||||||
|
|
||||||
json::iov content;
|
const auto update{[&out, &user_id, &deleted]
|
||||||
const json::iov::push push[]
|
(const auto &device_id)
|
||||||
{
|
{
|
||||||
{ content, { "user_id", user_id } },
|
json::iov content;
|
||||||
{ content, { "device_id", device_id } },
|
const json::iov::push push[]
|
||||||
{ content, { "deleted", deleted } },
|
{
|
||||||
|
{ content, { "user_id", user_id } },
|
||||||
|
{ content, { "device_id", device_id } },
|
||||||
|
{ content, { "deleted", deleted } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const bool broadcasted
|
||||||
|
{
|
||||||
|
m::user::devices::send(content)
|
||||||
|
};
|
||||||
|
|
||||||
|
out
|
||||||
|
<< "broadcast:"
|
||||||
|
<< broadcasted
|
||||||
|
<< ' '
|
||||||
|
<< device_id
|
||||||
|
<< std::endl;
|
||||||
|
}};
|
||||||
|
|
||||||
|
const bool found
|
||||||
|
{
|
||||||
|
!devices.for_each([&update, &device_id_]
|
||||||
|
(const auto &, const string_view &device_id)
|
||||||
|
{
|
||||||
|
if(device_id_ != "*" && device_id != device_id_)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
update(device_id);
|
||||||
|
return device_id != device_id_; // false to break
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const bool broadcasted
|
if(!found && deleted)
|
||||||
{
|
update(device_id_);
|
||||||
m::user::devices::send(content)
|
|
||||||
};
|
|
||||||
|
|
||||||
out << "done" << std::endl;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue