0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 08:24:08 +01:00

ircd:Ⓜ️:room::state: Add additional event::idx based tools.

This commit is contained in:
Jason Volk 2019-08-20 21:36:00 -07:00
parent 224c67032a
commit 7e8d8666ff
2 changed files with 60 additions and 0 deletions

View file

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

View file

@ -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