From 8e90f8de5d017fcc48283f4dd58a2dd8d6a15210 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 6 May 2019 20:47:12 -0700 Subject: [PATCH] ircd::m::room::state: Add convenience to check if state event. --- include/ircd/m/room/state.h | 2 ++ ircd/m_room.cc | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/ircd/m/room/state.h b/include/ircd/m/room/state.h index 41b96e8f6..fcf4f37bb 100644 --- a/include/ircd/m/room/state.h +++ b/include/ircd/m/room/state.h @@ -109,4 +109,6 @@ struct ircd::m::room::state static size_t rebuild_present(const state &); static bool force_present(const event &); static size_t purge_replaced(const state &); + static bool is(std::nothrow_t, const event::idx &); + static bool is(const event::idx &); }; diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 372518d96..687f077a0 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -36,6 +36,33 @@ ircd::m::room::purge(const room &room) return ret; } +bool +ircd::m::room::state::is(const event::idx &event_idx) +{ + bool ret{false}; + m::get(event_idx, "state_key", [&ret] + (const string_view &state_key) + { + ret = true; + }); + + return ret; +} + +bool +ircd::m::room::state::is(std::nothrow_t, + const event::idx &event_idx) +{ + bool ret{false}; + m::get(std::nothrow, event_idx, "state_key", [&ret] + (const string_view &state_key) + { + ret = true; + }); + + return ret; +} + size_t ircd::m::room::state::purge_replaced(const state &state) {