mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
modules: Add preliminary m_room_aliases protocol suite.
This commit is contained in:
parent
912562f469
commit
eb603c22c1
2 changed files with 110 additions and 0 deletions
|
@ -90,6 +90,7 @@ m_room_member_la_SOURCES = m_room_member.cc
|
|||
m_room_join_rules_la_SOURCES = m_room_join_rules.cc
|
||||
m_room_history_visibility_la_SOURCES = m_room_history_visibility.cc
|
||||
m_room_canonical_alias_la_SOURCES = m_room_canonical_alias.cc
|
||||
m_room_aliases_la_SOURCES = m_room_aliases.cc
|
||||
|
||||
m_module_LTLIBRARIES = \
|
||||
m_noop.la \
|
||||
|
@ -102,6 +103,7 @@ m_module_LTLIBRARIES = \
|
|||
m_room_join_rules.la \
|
||||
m_room_history_visibility.la \
|
||||
m_room_canonical_alias.la \
|
||||
m_room_aliases.la \
|
||||
###
|
||||
|
||||
###############################################################################
|
||||
|
|
108
modules/m_room_aliases.cc
Normal file
108
modules/m_room_aliases.cc
Normal file
|
@ -0,0 +1,108 @@
|
|||
// 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.aliases"
|
||||
};
|
||||
|
||||
const m::room::id::buf
|
||||
alias_room_id
|
||||
{
|
||||
"alias", ircd::my_host()
|
||||
};
|
||||
|
||||
const m::room
|
||||
alias_room
|
||||
{
|
||||
alias_room_id
|
||||
};
|
||||
|
||||
void
|
||||
_changed_aliases(const m::event &event)
|
||||
{
|
||||
const m::room::id &room_id
|
||||
{
|
||||
at<"room_id"_>(event)
|
||||
};
|
||||
|
||||
const json::array &aliases
|
||||
{
|
||||
at<"content"_>(event).get("aliases")
|
||||
};
|
||||
|
||||
for(const json::string &alias_ : aliases)
|
||||
{
|
||||
const m::room::alias &alias{alias_};
|
||||
const auto event_id
|
||||
{
|
||||
send(alias_room, m::me.user_id, "ircd.alias", alias, json::strung{event})
|
||||
};
|
||||
|
||||
log::info
|
||||
{
|
||||
"Updated aliases of %s by %s in %s [%s] => %s",
|
||||
string_view{room_id},
|
||||
json::get<"sender"_>(event),
|
||||
json::get<"event_id"_>(event),
|
||||
string_view{alias},
|
||||
string_view{event_id}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const m::hookfn<>
|
||||
_changed_aliases_hookfn
|
||||
{
|
||||
_changed_aliases,
|
||||
{
|
||||
{ "_site", "vm.notify" },
|
||||
{ "type", "m.room.aliases" },
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
_can_change_aliases(const m::event &event)
|
||||
{
|
||||
const m::room::id &room_id
|
||||
{
|
||||
at<"room_id"_>(event)
|
||||
};
|
||||
|
||||
const json::array &aliases
|
||||
{
|
||||
at<"content"_>(event).get("aliases")
|
||||
};
|
||||
|
||||
for(const json::string &alias_ : aliases)
|
||||
{
|
||||
const m::room::alias &alias{alias_};
|
||||
if(at<"origin"_>(event) != alias.host())
|
||||
throw m::ACCESS_DENIED
|
||||
{
|
||||
"Cannot set alias for host '%s' from origin '%s'",
|
||||
alias.host(),
|
||||
at<"origin"_>(event)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const m::hookfn<>
|
||||
_can_change_aliases_hookfn
|
||||
{
|
||||
_can_change_aliases,
|
||||
{
|
||||
{ "_site", "vm.eval" },
|
||||
{ "type", "m.room.aliases" },
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue