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

This commit is contained in:
Andriy Kushnir (Orhideous) 2022-11-28 01:44:05 +02:00
parent 5c0b0cdc64
commit 297c716807
No known key found for this signature in database
GPG key ID: 62E078AB621B0D15

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))
}
};