From 05b24b1ef3516b044deeb488d0f55a166f7e250e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 23 Apr 2020 01:47:13 -0700 Subject: [PATCH] modules/federation/sender: Add the special case to ensure sends after kicks/bans. --- modules/federation/sender.cc | 39 +++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/modules/federation/sender.cc b/modules/federation/sender.cc index 91fc09e4b..d354563e0 100644 --- a/modules/federation/sender.cc +++ b/modules/federation/sender.cc @@ -194,12 +194,19 @@ void send_to_room(const m::event &event, const m::room::id &room_id) { + const m::room room + { + room_id + }; + + const m::room::origins origins + { + room + }; + // Unit is not allocated until we find another server in the room. std::shared_ptr unit; - - const m::room room{room_id}; - const m::room::origins origins{room}; - origins.for_each([&unit, &event] + const auto each_origin{[&unit, &event] (const string_view &origin) { if(my_host(origin)) @@ -223,7 +230,29 @@ send_to_room(const m::event &event, node.push(unit); node.flush(); - }); + }}; + + // Iterate all servers with a joined user + origins.for_each(each_origin); + + // Special case for negative membership changes (i.e kicks and bans) + // which may remove a server from the above iteration + if(json::get<"type"_>(event) == "m.room.member") + if(m::membership(event, m::membership_negative)) + { + const m::user::id &target + { + at<"state_key"_>(event) + }; + + const string_view &origin + { + target.host() + }; + + if(!origins.has(origin)) + each_origin(origin); + } } /// EDU path where the target is a user/device