0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

modules/m_room: Fix/improve is_complete calculation.

This commit is contained in:
Jason Volk 2019-04-23 13:29:49 -07:00
parent 8208a67e7f
commit 93e3431915

View file

@ -481,48 +481,42 @@ std::pair<bool, int64_t>
IRCD_MODULE_EXPORT IRCD_MODULE_EXPORT
ircd::m::is_complete(const room &room) ircd::m::is_complete(const room &room)
{ {
static const event::keys::include fkeys room::messages it
{
"depth"
};
static const event::fetch::opts fopts
{
fkeys, { db::get::NO_CACHE }
};
const room::state state
{ {
room room
}; };
const auto create_idx const auto head_depth
{ {
state.get("m.room.create") int64_t(it.depth())
}; };
room::messages it int64_t depth(head_depth), last(depth + 1);
for(;; --it)
{ {
room, create_idx, &fopts if(!it || !m::get(it.event_idx(), "depth", depth))
}; break;
int64_t depth(-1); if(depth == last)
if(!it) continue;
return { false, depth };
for(; it; ++it) if(depth + 1 != last)
{ break;
const event &event{*it};
if(at<"depth"_>(event) == depth + 1)
++depth;
else if(depth < 0)
depth = at<"depth"_>(event);
if(at<"depth"_>(event) != depth) --last;
return { false, depth };
} }
return { true, depth }; if(depth > 1)
return {false, depth};
int64_t create_depth(0);
const room::state state(room);
const auto create_idx(state.get("m.room.create"));
m::get(create_idx, "depth", create_depth);
return
{
last == create_depth + 1, depth
};
} }
size_t size_t