diff --git a/include/ircd/m/room.h b/include/ircd/m/room.h index 00baa508e..c3f4bd43d 100644 --- a/include/ircd/m/room.h +++ b/include/ircd/m/room.h @@ -196,6 +196,7 @@ struct ircd::m::room::messages const m::event &fetch(std::nothrow_t); const m::event &fetch(); + bool seek_idx(const event::idx &); bool seek(const uint64_t &depth); bool seek(const event::id &); bool seek(); diff --git a/ircd/m/room.cc b/ircd/m/room.cc index 67ab4a619..80bba7f7d 100644 --- a/ircd/m/room.cc +++ b/ircd/m/room.cc @@ -553,31 +553,12 @@ bool ircd::m::room::messages::seek(const event::id &event_id) try { - auto &column - { - dbs::event_column.at(json::indexof()) - }; - - const event::idx event_idx + const event::idx &event_idx { index(event_id) }; - uint64_t depth; - column(byte_view(event_idx), [&depth] - (const string_view &value) - { - depth = byte_view(value); - }); - - char buf[dbs::ROOM_EVENTS_KEY_MAX_SIZE]; - const auto seek_key - { - dbs::room_events_key(buf, room.room_id, depth, event_idx) - }; - - this->it = dbs::room_events.begin(seek_key); - return bool(*this); + return seek_idx(event_idx); } catch(const db::not_found &e) { @@ -597,6 +578,37 @@ ircd::m::room::messages::seek(const uint64_t &depth) return bool(*this); } +bool +ircd::m::room::messages::seek_idx(const event::idx &event_idx) +try +{ + uint64_t depth; + m::get(event_idx, "depth", mutable_buffer + { + reinterpret_cast(&depth), sizeof(depth) + }); + + char buf[dbs::ROOM_EVENTS_KEY_MAX_SIZE]; + const auto &seek_key + { + dbs::room_events_key(buf, room.room_id, depth, event_idx) + }; + + this->it = dbs::room_events.begin(seek_key); + if(!bool(*this)) + return false; + + // Check if this event_idx is actually in this room + if(event_idx != this->event_idx()) + return false; + + return true; +} +catch(const db::not_found &e) +{ + return false; +} + ircd::m::event::id::buf ircd::m::room::messages::event_id() {