From d47e1761ecb7db8e570fb68d72a942e41001850b Mon Sep 17 00:00:00 2001 From: Nyaaori <+@nyaaori.cat> Date: Sat, 26 Nov 2022 13:03:19 +0100 Subject: [PATCH] fix: Proper S2S Backfill visibility handling --- src/service/rooms/state_accessor/mod.rs | 34 ++++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index ce8bb2b9..3b1f7060 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -112,10 +112,25 @@ impl Service { }); let visibility = match history_visibility { - Some(HistoryVisibility::Joined) => { - // Look at all members in the room from this server; one of them - // triggered a backfill. Was one of them a member in the past, - // at this event? + Some(HistoryVisibility::WorldReadable) => { + // Allow if event was sent while world readable + true + } + Some(HistoryVisibility::Invited) => { + let mut visible = false; + // Allow if any member on requesting server was invited or joined, else deny + for member in current_server_members { + if self.user_was_invited(shortstatehash, &member)? + || self.user_was_joined(shortstatehash, &member)? + { + visible = true; + break; + } + } + visible + } + _ => { + // Allow if any member on requested server was joined, else deny let mut visible = false; for member in current_server_members { if self.user_was_joined(shortstatehash, &member)? { @@ -125,17 +140,6 @@ impl Service { } visible } - Some(HistoryVisibility::Invited) => { - let mut visible = false; - for member in current_server_members { - if self.user_was_invited(shortstatehash, &member)? { - visible = true; - break; - } - } - visible - } - _ => false, }; self.server_visibility_cache