2018-05-13 05:22:22 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Matrix m.room.join_rules"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2018-10-07 07:17:46 +02:00
|
|
|
_changed_rules(const m::event &event,
|
2023-02-17 22:03:38 +01:00
|
|
|
m::vm::eval &eval)
|
2018-05-13 05:22:22 +02:00
|
|
|
{
|
2023-02-17 22:03:38 +01:00
|
|
|
const json::string new_rule
|
2018-05-13 05:22:22 +02:00
|
|
|
{
|
2023-02-17 22:03:38 +01:00
|
|
|
json::get<"content"_>(event).get("join_rule")
|
2018-05-13 05:22:22 +02:00
|
|
|
};
|
|
|
|
|
2023-02-17 22:03:38 +01:00
|
|
|
// Whether the room transitioned from public to private
|
|
|
|
const bool privatized
|
2018-05-13 05:22:22 +02:00
|
|
|
{
|
2023-02-17 22:03:38 +01:00
|
|
|
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";
|
|
|
|
})
|
2018-05-13 05:22:22 +02:00
|
|
|
};
|
|
|
|
|
2023-02-17 22:03:38 +01:00
|
|
|
// Delete the entry in the room directory for the no-longer-public room
|
|
|
|
if(privatized)
|
2018-05-13 05:22:22 +02:00
|
|
|
{
|
2023-02-17 22:03:38 +01:00
|
|
|
const m::room::id &room_id
|
|
|
|
{
|
|
|
|
at<"room_id"_>(event)
|
|
|
|
};
|
2018-05-13 05:22:22 +02:00
|
|
|
|
2023-02-17 22:03:38 +01:00
|
|
|
m::rooms::summary::del(room_id);
|
|
|
|
}
|
2018-05-13 05:22:22 +02:00
|
|
|
}
|
|
|
|
|
2019-08-10 06:27:12 +02:00
|
|
|
m::hookfn<m::vm::eval &>
|
2018-05-13 05:22:22 +02:00
|
|
|
_changed_rules_hookfn
|
|
|
|
{
|
|
|
|
_changed_rules,
|
|
|
|
{
|
2018-10-07 07:17:46 +02:00
|
|
|
{ "_site", "vm.effect" },
|
2018-05-13 05:22:22 +02:00
|
|
|
{ "type", "m.room.join_rules" },
|
|
|
|
}
|
|
|
|
};
|
2018-10-26 03:07:46 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
_changed_rules_notify(const m::event &event,
|
|
|
|
m::vm::eval &)
|
|
|
|
{
|
|
|
|
log::info
|
|
|
|
{
|
2018-12-23 02:44:18 +01:00
|
|
|
m::log, "%s changed join_rules in %s [%s] to %s",
|
2018-10-26 03:07:46 +02:00
|
|
|
json::get<"sender"_>(event),
|
|
|
|
json::get<"room_id"_>(event),
|
2019-07-06 07:01:34 +02:00
|
|
|
string_view{event.event_id},
|
2018-10-26 03:07:46 +02:00
|
|
|
json::get<"content"_>(event).get("join_rule"),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-10 06:27:12 +02:00
|
|
|
m::hookfn<m::vm::eval &>
|
2018-10-26 03:07:46 +02:00
|
|
|
_changed_rules_notify_hookfn
|
|
|
|
{
|
|
|
|
_changed_rules_notify,
|
|
|
|
{
|
|
|
|
{ "_site", "vm.notify" },
|
|
|
|
{ "type", "m.room.join_rules" },
|
|
|
|
}
|
|
|
|
};
|