0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 23:10:54 +01:00

modules/m_room_power_levels: Add preliminary power eval.

This commit is contained in:
Jason Volk 2018-10-31 12:24:58 -07:00
parent 7b307e6151
commit 2c957cc656

View file

@ -16,6 +16,94 @@ IRCD_MODULE
"Matrix m.room.power_levels" "Matrix m.room.power_levels"
}; };
static void
_has_power(const m::event &event,
m::vm::eval &)
{
const auto &room_id
{
json::get<"room_id"_>(event)
};
const auto &event_id
{
json::get<"event_id"_>(event)
};
if(!room_id || !event_id) // Not evaluated here
return;
const auto &type
{
at<"type"_>(event)
};
if(type == "m.room.create") // Checked by _can_create_room
return;
const m::room room
{
room_id //TODO: at event
};
const m::user::id &sender
{
at<"sender"_>(event)
};
//TODO: ircd.presence
if(my(event) && my(room) && !my(sender))
return;
const m::room::power power
{
room
};
const auto &state_key
{
json::get<"state_key"_>(event)
};
if(!power(sender, "events", type, state_key))
log::error //TODO: throw
{
"Power violation %s in %s for %s %s,%s",
string_view{sender},
string_view{room_id},
string_view{event_id},
type,
state_key
};
}
const m::hookfn<m::vm::eval &>
_has_power_hookfn
{
_has_power,
{
{ "_site", "vm.eval" },
}
};
static void
_can_change_levels(const m::event &event,
m::vm::eval &)
{
//TODO: abstract event check against existing power levels should
//TODO: cover this?
}
const m::hookfn<m::vm::eval &>
_can_change_levels_hookfn
{
_can_change_levels,
{
{ "_site", "vm.eval" },
{ "type", "m.room.power_levels" },
}
};
static void static void
_changed_levels(const m::event &event, _changed_levels(const m::event &event,
m::vm::eval &) m::vm::eval &)