0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-29 15:28:20 +02:00

modules/client/rooms: Add a state reindexer routine.

This commit is contained in:
Jason Volk 2018-05-13 19:16:08 -07:00
parent 8f3b84fff9
commit 5590238b1f

View file

@ -215,3 +215,43 @@ state__iov(const room &room,
return commit(room, event, content);
}
extern "C" size_t
state__rebuild_present(const m::room &room)
{
size_t ret{0};
const auto create_id
{
room::state{room}.get("m.room.create")
};
room::messages it
{
room, create_id
};
if(!it)
return ret;
db::txn txn{*dbs::events};
for(; it; ++it)
{
const event &event{*it};
if(!defined(json::get<"state_key"_>(event)))
continue;
dbs::write_opts opts;
opts.idx = it.event_idx();
opts.present = true;
opts.history = false;
opts.head = false;
opts.refs = false;
dbs::_index__room_state(txn, event, opts);
dbs::_index__room_joined(txn, event, opts);
++ret;
}
txn();
return ret;
}