refactor: Replace imperative style with short-circuit .any()

This commit is contained in:
Andriy Kushnir (Orhideous) 2022-11-28 01:44:05 +02:00 committed by Nyaaori
parent e3dcb668cf
commit 5987452cfc
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E

View file

@ -119,28 +119,16 @@ impl Service {
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 requesting server was AT LEAST invited, else deny
current_server_members
.into_iter()
.any(|member| self.user_was_invited(shortstatehash, &member))
}
_ => {
// 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)? {
visible = true;
break;
}
}
visible
current_server_members
.into_iter()
.any(|member| self.user_was_joined(shortstatehash, &member))
}
};