0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 00:02:34 +01:00

modules/console: Add redact state convenience; fix missing newline.

This commit is contained in:
Jason Volk 2023-04-20 12:42:14 -07:00
parent 1e42fa16a7
commit 502a03a8cf

View file

@ -18269,7 +18269,7 @@ console_cmd__redact__last(opt &out, const string_view &line)
<< redact_id
<< " redacted "
<< event_id
;
<< std::endl;
return --count > 0;
@ -18278,6 +18278,93 @@ console_cmd__redact__last(opt &out, const string_view &line)
return true;
}
bool
console_cmd__redact__state(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "redactor", "type", "state_key"
}};
const m::room::id::buf room_id
{
m::room_id(param.at("room_id"))
};
const m::user::id redactor
{
param.at("redactor")
};
const auto type
{
param["type"]
};
const auto state_key
{
param["state_key"]
};
const m::room room
{
room_id
};
if(state_key)
{
const auto event_idx
{
room.get(type, state_key)
};
const auto event_id
{
m::event_id(std::nothrow, event_idx)
};
const auto redact_id
{
m::redact(room, redactor, event_id, "console")
};
out
<< redact_id
<< " redacted "
<< event_id
<< std::endl;
return true;
}
const m::room::state state
{
room
};
state.for_each(type, [&out, &room, &redactor]
(const auto &, const auto &state_key, const m::event::idx &event_idx)
{
const auto event_id
{
m::event_id(std::nothrow, event_idx)
};
const auto redact_id
{
m::redact(room, redactor, event_id, "console")
};
out
<< redact_id
<< " redacted "
<< event_id
<< std::endl;
return true;
});
return true;
}
//
// well-known
//