From c352822d94275fb969dfbcc2059e1135cb8a5435 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 11 Jun 2018 23:49:44 -0700 Subject: [PATCH] modules/m_room: Add util to force event into present state w/ console cmd. --- modules/console.cc | 33 +++++++++++++++++++++++++++++++++ modules/m_room.cc | 29 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index 4d9daa115..20060c4b5 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -4498,6 +4498,39 @@ console_cmd__room__state(opt &out, const string_view &line) return true; } +bool +console_cmd__room__state__force(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "event_id" + }}; + + const m::event::id &event_id + { + param.at(0) + }; + + const m::event::fetch event + { + event_id + }; + + using prototype = bool (const m::event &); + static m::import state__force_present + { + "m_room", "state__force_present" + }; + + const auto res + { + state__force_present(event) + }; + + out << "forced " << event_id << " into present state" << std::endl; + return true; +} + bool console_cmd__room__state__rebuild__present(opt &out, const string_view &line) { diff --git a/modules/m_room.cc b/modules/m_room.cc index 3fa705ddb..c9708eab0 100644 --- a/modules/m_room.cc +++ b/modules/m_room.cc @@ -185,6 +185,35 @@ is_complete(const m::room &room) return {true, depth}; } +extern "C" bool +state__force_present(const m::event &event) +{ + db::txn txn + { + *m::dbs::events + }; + + if(!defined(json::get<"state_key"_>(event))) + throw error + { + "event %s is not a state event (no state_key)", + json::get<"event_id"_>(event) + }; + + m::dbs::write_opts opts; + opts.event_idx = index(event); + opts.present = true; + opts.history = false; + opts.head = false; + opts.refs = false; + + m::dbs::_index__room_state(txn, event, opts); + m::dbs::_index__room_joined(txn, event, opts); + + txn(); + return true; +} + extern "C" size_t state__rebuild_present(const m::room &room) {