From aca6aae5fd82428c631231c8eccc301b250031d3 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 11 Nov 2020 15:33:48 -0800 Subject: [PATCH] modules/m_room_tombstone: Invalidate alias cache entries for effect. --- matrix/matrix.cc | 1 + modules/Makefile.am | 2 ++ modules/m_room_tombstone.cc | 58 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 modules/m_room_tombstone.cc diff --git a/matrix/matrix.cc b/matrix/matrix.cc index c73d7ebf1..7cdc6a77b 100644 --- a/matrix/matrix.cc +++ b/matrix/matrix.cc @@ -85,6 +85,7 @@ ircd::m::matrix::module_names "m_room_redaction", "m_room_server_acl", "m_room_third_party_invite", + "m_room_tombstone", "media_media", diff --git a/modules/Makefile.am b/modules/Makefile.am index 9311bd076..05699d862 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -104,6 +104,7 @@ m_room_power_levels_la_SOURCES = m_room_power_levels.cc m_room_redaction_la_SOURCES = m_room_redaction.cc m_room_server_acl_la_SOURCES = m_room_server_acl.cc m_room_third_party_invite_la_SOURCES = m_room_third_party_invite.cc +m_room_tombstone_la_SOURCES = m_room_tombstone.cc m_module_LTLIBRARIES = \ m_breadcrumbs.la \ @@ -135,6 +136,7 @@ m_module_LTLIBRARIES = \ m_room_redaction.la \ m_room_server_acl.la \ m_room_third_party_invite.la \ + m_room_tombstone.la \ ### ############################################################################### diff --git a/modules/m_room_tombstone.cc b/modules/m_room_tombstone.cc new file mode 100644 index 000000000..2d7a7431d --- /dev/null +++ b/modules/m_room_tombstone.cc @@ -0,0 +1,58 @@ +// The Construct +// +// Copyright (C) The Construct Developers, Authors & Contributors +// Copyright (C) 2016-2020 Jason Volk +// +// 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. + +namespace ircd::m +{ + static void room_tombstone_effect_handler(const event &, vm::eval &); + extern hookfn room_tombstone_effect_hook; +} + +ircd::mapi::header +IRCD_MODULE +{ + "Matrix m.room.tombstone" +}; + +decltype(ircd::m::room_tombstone_effect_hook) +ircd::m::room_tombstone_effect_hook +{ + room_tombstone_effect_handler, + { + { "_site", "vm.effect" }, + { "type", "m.room.tombstone" }, + } +}; + +void +ircd::m::room_tombstone_effect_handler(const m::event &event, + m::vm::eval &) +{ + assert(at<"type"_>(event) == "m.room.tombstone"); + + const m::room room + { + at<"room_id"_>(event) + }; + + if(!creator(room, at<"sender"_>(event))) + return; + + const m::room::aliases aliases + { + room + }; + + aliases.for_each([](const auto &room_alias) + { + // Invalidate the alias cache immediately so we don't have to wait a TTL + m::room::aliases::cache::del(room_alias); + return true; + }); +}