mirror of
https://github.com/matrix-construct/construct
synced 2025-03-17 06:50:23 +01:00
modules/m_room_canonical_alias: Improve cache manip in effect hook.
This commit is contained in:
parent
f64f41775d
commit
dc302601fb
1 changed files with 43 additions and 9 deletions
|
@ -32,30 +32,64 @@ void
|
|||
_changed_canonical_alias(const m::event &event,
|
||||
m::vm::eval &)
|
||||
{
|
||||
const m::room::alias &alias
|
||||
{
|
||||
unquote(at<"content"_>(event).at("alias"))
|
||||
};
|
||||
|
||||
const m::room::id &room_id
|
||||
{
|
||||
at<"room_id"_>(event)
|
||||
};
|
||||
|
||||
const auto event_id
|
||||
const m::room room
|
||||
{
|
||||
send(alias_room, m::me.user_id, "ircd.alias", alias, json::strung{event})
|
||||
room_id, event.event_id
|
||||
};
|
||||
|
||||
const json::object &content
|
||||
{
|
||||
at<"content"_>(event)
|
||||
};
|
||||
|
||||
const m::room::alias &alias
|
||||
{
|
||||
content.has("alias")?
|
||||
m::room::alias{unquote(content.get("alias"))}:
|
||||
m::room::alias{}
|
||||
};
|
||||
|
||||
log::info
|
||||
{
|
||||
m::log, "Changed canonical alias of %s to %s by %s with %s => %s",
|
||||
m::log, "Changed canonical alias of %s to %s by %s with %s",
|
||||
string_view{room_id},
|
||||
string_view{alias},
|
||||
json::get<"sender"_>(event),
|
||||
string_view{event.event_id},
|
||||
string_view{event_id}
|
||||
};
|
||||
|
||||
if(alias)
|
||||
{
|
||||
if(m::room::aliases::cache::has(alias))
|
||||
return;
|
||||
|
||||
m::room::aliases::cache::set(alias, room_id);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto event_idx
|
||||
{
|
||||
room.get(std::nothrow, "m.room.canonical_alias", "")
|
||||
};
|
||||
|
||||
if(!event_idx)
|
||||
return;
|
||||
|
||||
m::get(std::nothrow, event_idx, "content", []
|
||||
(const json::object &content)
|
||||
{
|
||||
const json::string &alias
|
||||
{
|
||||
content["alias"]
|
||||
};
|
||||
|
||||
m::room::aliases::cache::del(alias);
|
||||
});
|
||||
}
|
||||
|
||||
const m::hookfn<m::vm::eval &>
|
||||
|
|
Loading…
Add table
Reference in a new issue