From def97cf25bacdc5d339dd31c2ae7e9d14616bcd6 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 7 Jun 2019 05:29:56 -0700 Subject: [PATCH] modules/client/rooms/join: Improve lazy chain member event search. --- modules/client/rooms/join.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/client/rooms/join.cc b/modules/client/rooms/join.cc index a39ea91a6..69cd58ca3 100644 --- a/modules/client/rooms/join.cc +++ b/modules/client/rooms/join.cc @@ -485,16 +485,17 @@ bootstrap_eval_lazy_chain(const json::array &auth_chain) // the vm certain member events first to avoid complications; this // subroutine will find them. const auto find_member{[&events] - (const m::user::id &user_id) + (const m::user::id &user_id, const int64_t &depth) { - const auto it(std::find_if(begin(events), end(events), [&user_id] + const auto it(std::find_if(rbegin(events), rend(events), [&user_id, &depth] (const m::event &event) { - return json::get<"type"_>(event) == "m.room.member" && + return json::get<"depth"_>(event) < depth && + json::get<"type"_>(event) == "m.room.member" && json::get<"state_key"_>(event) == user_id; })); - if(unlikely(it == end(events))) + if(unlikely(it == rend(events))) throw m::NOT_FOUND { "No m.room.member event for %s found in auth chain.", @@ -518,7 +519,7 @@ bootstrap_eval_lazy_chain(const json::array &auth_chain) { const auto &member_event { - find_member(at<"sender"_>(event)) + find_member(at<"sender"_>(event), at<"depth"_>(event)) }; m::vm::eval