0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

ircd:Ⓜ️:dbs: Add reference index type for m.room.redaction.

This commit is contained in:
Jason Volk 2019-03-10 14:52:11 -07:00
parent 7434a4b6db
commit a55c549e70
2 changed files with 52 additions and 0 deletions

View file

@ -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 &);

View file

@ -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 "????";