2018-06-12 07:43:19 +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.canonical_alias"
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::id::buf
|
|
|
|
alias_room_id
|
|
|
|
{
|
|
|
|
"alias", ircd::my_host()
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room
|
|
|
|
alias_room
|
|
|
|
{
|
|
|
|
alias_room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2018-10-07 07:17:46 +02:00
|
|
|
_changed_canonical_alias(const m::event &event,
|
|
|
|
m::vm::eval &)
|
2018-06-12 07:43:19 +02:00
|
|
|
{
|
2019-07-20 04:48:38 +02:00
|
|
|
const m::room::id &room_id
|
2018-06-12 07:43:19 +02:00
|
|
|
{
|
2019-07-20 04:48:38 +02:00
|
|
|
at<"room_id"_>(event)
|
2018-06-12 07:43:19 +02:00
|
|
|
};
|
|
|
|
|
2019-07-20 04:48:38 +02:00
|
|
|
const m::room room
|
2018-06-12 07:43:19 +02:00
|
|
|
{
|
2019-07-20 04:48:38 +02:00
|
|
|
room_id, event.event_id
|
2018-06-12 07:43:19 +02:00
|
|
|
};
|
|
|
|
|
2019-07-20 04:48:38 +02:00
|
|
|
const json::object &content
|
2018-06-12 07:43:19 +02:00
|
|
|
{
|
2019-07-20 04:48:38 +02:00
|
|
|
at<"content"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::alias &alias
|
|
|
|
{
|
|
|
|
content.has("alias")?
|
|
|
|
m::room::alias{unquote(content.get("alias"))}:
|
|
|
|
m::room::alias{}
|
2018-06-12 07:43:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
log::info
|
|
|
|
{
|
2019-07-20 04:48:38 +02:00
|
|
|
m::log, "Changed canonical alias of %s to %s by %s with %s",
|
2018-06-12 07:43:19 +02:00
|
|
|
string_view{room_id},
|
|
|
|
string_view{alias},
|
|
|
|
json::get<"sender"_>(event),
|
2019-07-06 07:01:34 +02:00
|
|
|
string_view{event.event_id},
|
2018-06-12 07:43:19 +02:00
|
|
|
};
|
2019-07-20 04:48:38 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2018-06-12 07:43:19 +02:00
|
|
|
}
|
|
|
|
|
2018-10-07 07:17:46 +02:00
|
|
|
const m::hookfn<m::vm::eval &>
|
2018-06-12 07:43:19 +02:00
|
|
|
_changed_canonical_alias_hookfn
|
|
|
|
{
|
|
|
|
_changed_canonical_alias,
|
|
|
|
{
|
2018-10-07 07:17:46 +02:00
|
|
|
{ "_site", "vm.effect" },
|
2018-06-12 07:43:19 +02:00
|
|
|
{ "type", "m.room.canonical_alias" },
|
|
|
|
}
|
|
|
|
};
|