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:
parent
c7033a4df1
commit
92ca127f54
1 changed files with 24 additions and 14 deletions
|
@ -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 &>
|
||||
|
|
Loading…
Reference in a new issue