0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

modules/m_room_join_rules: Refactor effect hook to remove public->invite rooms from directory.

This commit is contained in:
Jason Volk 2023-02-17 13:03:38 -08:00
parent c7033a4df1
commit 92ca127f54

View file

@ -18,29 +18,39 @@ IRCD_MODULE
static void
_changed_rules(const m::event &event,
m::vm::eval &)
m::vm::eval &eval)
{
const m::user::id &sender
const json::string new_rule
{
at<"sender"_>(event)
json::get<"content"_>(event).get("join_rule")
};
if(!my(sender))
return;
const m::room::id::buf public_room
// Whether the room transitioned from public to private
const bool privatized
{
"public", my_host()
new_rule == "invite" &&
m::query(std::nothrow, m::room::state::prev(eval.sequence), "content", false, []
(const json::object &content)
{
const json::string old_rule
{
content["join_rule"]
};
return old_rule == "public";
})
};
// Delete the entry in the room directory for the no-longer-public room
if(privatized)
{
const m::room::id &room_id
{
at<"room_id"_>(event)
};
// This call sends a message to the !public room to list this room in the
// public rooms list.
m::rooms::summary::set(room_id);
m::rooms::summary::del(room_id);
}
}
m::hookfn<m::vm::eval &>