diff --git a/include/ircd/m/room/state.h b/include/ircd/m/room/state.h index ad4cb5f92..5defe28e7 100644 --- a/include/ircd/m/room/state.h +++ b/include/ircd/m/room/state.h @@ -69,6 +69,7 @@ struct ircd::m::room::state // Existential bool has(const string_view &type, const string_view &state_key) const; bool has(const string_view &type) const; + bool has(const event::idx &) const; // Fetch a state event bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::closure_idx &) const; @@ -95,6 +96,7 @@ struct ircd::m::room::state static event::idx next(const event::idx &); static size_t prefetch(const state &, const string_view &, const event::idx_range &); + static bool present(const event::idx &); static size_t rebuild_present(const room::id &); static bool force_present(const event &); static size_t purge_replaced(const room::id &); diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 327232131..1edf2ce91 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -170,6 +170,38 @@ ircd::m::room::state::rebuild_present(const room::id &room_id) return ret; } +bool +ircd::m::room::state::present(const event::idx &event_idx) +{ + static const event::fetch::opts fopts + { + event::keys::include { "room_id", "type", "state_key" }, + }; + + const m::event::fetch event + { + event_idx, fopts + }; + + const m::room room + { + at<"room_id"_>(event) + }; + + const m::room::state state + { + room + }; + + const auto state_idx + { + state.get(std::nothrow, at<"type"_>(event), at<"state_key"_>(event)) + }; + + assert(event_idx); + return state_idx == event_idx; +} + size_t ircd::m::room::state::prefetch(const state &state, const string_view &type, @@ -2141,6 +2173,32 @@ const }); } +bool +ircd::m::room::state::has(const event::idx &event_idx) +const +{ + static const event::fetch::opts fopts + { + event::keys::include { "type", "state_key" }, + }; + + const m::event::fetch event + { + event_idx, std::nothrow, fopts + }; + + if(!event.valid) + return false; + + const auto state_idx + { + get(std::nothrow, at<"type"_>(event), at<"state_key"_>(event)) + }; + + assert(event_idx); + return event_idx == state_idx; +} + bool ircd::m::room::state::has(const string_view &type) const