diff --git a/include/ircd/m/dbs.h b/include/ircd/m/dbs.h index 082dddf87..053d997bb 100644 --- a/include/ircd/m/dbs.h +++ b/include/ircd/m/dbs.h @@ -153,6 +153,9 @@ enum class ircd::m::dbs::ref // m.relates_to M_RELATES__M_REPLY = 0x20, + + // m.room.redaction + M_ROOM_REDACTION = 0x40, }; /// Database Schema Descriptors @@ -299,6 +302,7 @@ namespace ircd::m::dbs string_view _index_redact(db::txn &, const event &, const write_opts &); string_view _index_other(db::txn &, const event &, const write_opts &); string_view _index_room(db::txn &, const event &, const write_opts &); + void _index_event_refs_m_room_redaction(db::txn &, const event &, const write_opts &); void _index_event_refs_m_receipt_m_read(db::txn &, const event &, const write_opts &); void _index_event_refs_m_relates_m_reply(db::txn &, const event &, const write_opts &); void _index_event_refs_auth(db::txn &, const event &, const write_opts &); diff --git a/ircd/m_dbs.cc b/ircd/m_dbs.cc index d7fd1e507..a40ec1c88 100644 --- a/ircd/m_dbs.cc +++ b/ircd/m_dbs.cc @@ -360,6 +360,9 @@ ircd::m::dbs::_index_event_refs(db::txn &txn, if(opts.event_refs.test(uint(ref::M_RELATES__M_REPLY))) _index_event_refs_m_relates_m_reply(txn, event, opts); + + if(opts.event_refs.test(uint(ref::M_ROOM_REDACTION))) + _index_event_refs_m_room_redaction(txn, event, opts); } void @@ -552,6 +555,48 @@ ircd::m::dbs::_index_event_refs_m_relates_m_reply(db::txn &txn, }; } +void +ircd::m::dbs::_index_event_refs_m_room_redaction(db::txn &txn, + const event &event, + const write_opts &opts) +{ + assert(opts.event_refs.test(uint(ref::M_ROOM_REDACTION))); + + if(json::get<"type"_>(event) != "m.room.redaction") + return; + + if(!valid(m::id::EVENT, json::get<"redacts"_>(event))) + return; + + const auto &event_id + { + json::get<"redacts"_>(event) + }; + + const event::idx &event_idx + { + m::index(event_id, std::nothrow) // query + }; + + if(!event_idx) + return; + + thread_local char buf[EVENT_REFS_KEY_MAX_SIZE]; + assert(opts.event_idx != 0 && event_idx != 0); + const string_view &key + { + event_refs_key(buf, event_idx, ref::M_ROOM_REDACTION, opts.event_idx) + }; + + db::txn::append + { + txn, dbs::event_refs, + { + opts.op, key, string_view{} + } + }; +} + ircd::string_view ircd::m::dbs::_index_room(db::txn &txn, const event &event, @@ -1221,6 +1266,9 @@ ircd::m::dbs::reflect(const ref &type) case ref::M_RELATES__M_REPLY: return "M_RELATES__M_REPLY"; + + case ref::M_ROOM_REDACTION: + return "M_ROOM_REDACTION"; } return "????";