0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

modules/m_room: Add head reset w/ console cmd.

This commit is contained in:
Jason Volk 2018-05-22 02:58:49 -07:00
parent 8e804ff48d
commit 4cc8ba0b79
2 changed files with 77 additions and 0 deletions

View file

@ -3123,6 +3123,39 @@ console_cmd__room__head__rebuild(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__room__head__reset(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id",
}};
const auto &room_id
{
m::room_id(param.at(0))
};
const m::room room
{
room_id
};
using prototype = size_t (const m::room &);
static m::import<prototype> head__reset
{
"m_room", "head__reset"
};
const size_t count
{
head__reset(room)
};
out << "done " << count << std::endl;
return true;
}
bool bool
console_cmd__room__depth(opt &out, const string_view &line) console_cmd__room__depth(opt &out, const string_view &line)
{ {

View file

@ -180,3 +180,47 @@ head__rebuild(const m::room &room)
txn(); txn();
return ret; return ret;
} }
extern "C" size_t
head__reset(const m::room &room)
{
size_t ret{0};
const m::room::state state{room};
const auto create_id
{
state.get("m.room.create")
};
m::room::messages it
{
room, create_id
};
if(!it)
return ret;
db::txn txn
{
*m::dbs::events
};
m::dbs::write_opts opts;
opts.op = db::op::DELETE;
opts.head = true;
for(; it; ++it)
{
const m::event &event{*it};
opts.event_idx = it.event_idx();
m::dbs::_index__room_head(txn, event, opts);
++ret;
}
{
opts.op = db::op::SET;
const m::event::fetch event{opts.event_idx};
m::dbs::_index__room_head(txn, event, opts);
}
txn();
return ret;
}