diff --git a/include/ircd/m/event.h b/include/ircd/m/event.h index 1c7ed0d9b..2026b2052 100644 --- a/include/ircd/m/event.h +++ b/include/ircd/m/event.h @@ -99,6 +99,14 @@ struct ircd::m::event::prev { enum cond :int; + std::tuple auth_events(const uint &idx) const; + std::tuple prev_states(const uint &idx) const; + std::tuple prev_events(const uint &idx) const; + + event::id auth_event(const uint &idx) const; + event::id prev_state(const uint &idx) const; + event::id prev_event(const uint &idx) const; + using super_type::tuple; using super_type::operator=; }; diff --git a/ircd/m/event.cc b/ircd/m/event.cc index 87d74f4f9..1b9fe0c5d 100644 --- a/ircd/m/event.cc +++ b/ircd/m/event.cc @@ -337,6 +337,76 @@ ircd::m::event::event(const id &id, new (this) m::event(obj); } +// +// event::prev +// + +ircd::m::event::id +ircd::m::event::prev::auth_event(const uint &idx) +const +{ + return std::get<0>(auth_events(idx)); +} + +ircd::m::event::id +ircd::m::event::prev::prev_state(const uint &idx) +const +{ + return std::get<0>(prev_states(idx)); +} + +ircd::m::event::id +ircd::m::event::prev::prev_event(const uint &idx) +const +{ + return std::get<0>(prev_events(idx)); +} + +std::tuple +ircd::m::event::prev::auth_events(const uint &idx) +const +{ + const json::array &auth_event + { + at<"auth_events"_>(*this).at(idx) + }; + + return + { + unquote(auth_event.at(0)), unquote(auth_event[1]) + }; +} + +std::tuple +ircd::m::event::prev::prev_states(const uint &idx) +const +{ + const json::array &state_event + { + at<"prev_state"_>(*this).at(idx) + }; + + return + { + unquote(state_event.at(0)), unquote(state_event[1]) + }; +} + +std::tuple +ircd::m::event::prev::prev_events(const uint &idx) +const +{ + const json::array &prev_event + { + at<"prev_events"_>(*this).at(idx) + }; + + return + { + unquote(prev_event.at(0)), unquote(prev_event[1]) + }; +} + // // event::fetch //