diff --git a/modules/m_room_power_levels.cc b/modules/m_room_power_levels.cc index ed4fb1e84..d7041d0b3 100644 --- a/modules/m_room_power_levels.cc +++ b/modules/m_room_power_levels.cc @@ -16,6 +16,94 @@ IRCD_MODULE "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 +_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 +_can_change_levels_hookfn +{ + _can_change_levels, + { + { "_site", "vm.eval" }, + { "type", "m.room.power_levels" }, + } +}; + static void _changed_levels(const m::event &event, m::vm::eval &)