chore: Use .is_some_and(…) instead of .map_or(false, …)
This commit is contained in:
parent
b2fe172be1
commit
bcae4e5799
@ -358,19 +358,18 @@ impl VersionHistory {
|
||||
|version: MatrixVersion| versions.iter().all(|v| v.is_superset_of(version));
|
||||
|
||||
// Check if all versions removed this endpoint.
|
||||
if self.removed.map_or(false, greater_or_equal_all) {
|
||||
if self.removed.is_some_and(greater_or_equal_all) {
|
||||
return VersioningDecision::Removed;
|
||||
}
|
||||
|
||||
// Check if *any* version marks this endpoint as stable.
|
||||
if self.added_in().map_or(false, greater_or_equal_any) {
|
||||
let all_deprecated = self.deprecated.map_or(false, greater_or_equal_all);
|
||||
if self.added_in().is_some_and(greater_or_equal_any) {
|
||||
let all_deprecated = self.deprecated.is_some_and(greater_or_equal_all);
|
||||
|
||||
return VersioningDecision::Stable {
|
||||
any_deprecated: all_deprecated
|
||||
|| self.deprecated.map_or(false, greater_or_equal_any),
|
||||
any_deprecated: all_deprecated || self.deprecated.is_some_and(greater_or_equal_any),
|
||||
all_deprecated,
|
||||
any_removed: self.removed.map_or(false, greater_or_equal_any),
|
||||
any_removed: self.removed.is_some_and(greater_or_equal_any),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -115,10 +115,10 @@ impl Ruleset {
|
||||
if rule_id.contains('\\') {
|
||||
return Err(InsertPushRuleError::InvalidRuleId);
|
||||
}
|
||||
if after.map_or(false, |s| s.starts_with('.')) {
|
||||
if after.is_some_and(|s| s.starts_with('.')) {
|
||||
return Err(InsertPushRuleError::RelativeToServerDefaultRule);
|
||||
}
|
||||
if before.map_or(false, |s| s.starts_with('.')) {
|
||||
if before.is_some_and(|s| s.starts_with('.')) {
|
||||
return Err(InsertPushRuleError::RelativeToServerDefaultRule);
|
||||
}
|
||||
|
||||
@ -291,7 +291,7 @@ impl Ruleset {
|
||||
) -> Option<AnyPushRuleRef<'_>> {
|
||||
let event = FlattenedJson::from_raw(event);
|
||||
|
||||
if event.get_str("sender").map_or(false, |sender| sender == context.user_id) {
|
||||
if event.get_str("sender").is_some_and(|sender| sender == context.user_id) {
|
||||
// no need to look at the rules if the event was by the user themselves
|
||||
None
|
||||
} else {
|
||||
@ -619,7 +619,7 @@ impl PatternedPushRule {
|
||||
return false;
|
||||
}
|
||||
|
||||
if event.get_str("sender").map_or(false, |sender| sender == context.user_id) {
|
||||
if event.get_str("sender").is_some_and(|sender| sender == context.user_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ impl PushCondition {
|
||||
/// * `event` - The flattened JSON representation of a room message event.
|
||||
/// * `context` - The context of the room at the time of the event.
|
||||
pub fn applies(&self, event: &FlattenedJson, context: &PushConditionRoomCtx) -> bool {
|
||||
if event.get_str("sender").map_or(false, |sender| sender == context.user_id) {
|
||||
if event.get_str("sender").is_some_and(|sender| sender == context.user_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -198,11 +198,11 @@ impl PushCondition {
|
||||
}
|
||||
RoomVersionFeature::_Custom(_) => false,
|
||||
},
|
||||
Self::EventPropertyIs { key, value } => event.get(key).map_or(false, |v| v == value),
|
||||
Self::EventPropertyIs { key, value } => event.get(key).is_some_and(|v| v == value),
|
||||
Self::EventPropertyContains { key, value } => event
|
||||
.get(key)
|
||||
.and_then(FlattenedJsonValue::as_array)
|
||||
.map_or(false, |a| a.contains(value)),
|
||||
.is_some_and(|a| a.contains(value)),
|
||||
Self::_Custom(_) => false,
|
||||
}
|
||||
}
|
||||
@ -395,7 +395,7 @@ impl StrExt for str {
|
||||
|
||||
// Look if the match has word boundaries.
|
||||
let word_boundary_start = !self.char_at(start).is_word_char()
|
||||
|| self.find_prev_char(start).map_or(true, |c| !c.is_word_char());
|
||||
|| !self.find_prev_char(start).is_some_and(|c| c.is_word_char());
|
||||
|
||||
if word_boundary_start {
|
||||
let word_boundary_end = end == self.len()
|
||||
|
@ -221,7 +221,7 @@ impl<'a> AnyPushRuleRef<'a> {
|
||||
/// * `event` - The flattened JSON representation of a room message event.
|
||||
/// * `context` - The context of the room at the time of the event.
|
||||
pub fn applies(self, event: &FlattenedJson, context: &PushConditionRoomCtx) -> bool {
|
||||
if event.get_str("sender").map_or(false, |sender| sender == context.user_id) {
|
||||
if event.get_str("sender").is_some_and(|sender| sender == context.user_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ impl TryFrom<ContentMeta> for ContentAttrs {
|
||||
));
|
||||
}
|
||||
|
||||
if prefix.is_some() && !event_kind.map_or(false, |k| k.is_account_data()) {
|
||||
if prefix.is_some() && !event_kind.is_some_and(|k| k.is_account_data()) {
|
||||
return Err(syn::Error::new_spanned(
|
||||
event_type,
|
||||
"only account data events may contain a `.*` suffix",
|
||||
|
@ -719,7 +719,7 @@ fn can_send_event(event: impl Event, ple: Option<impl Event>, user_level: Int) -
|
||||
return false;
|
||||
}
|
||||
|
||||
if event.state_key().map_or(false, |k| k.starts_with('@'))
|
||||
if event.state_key().is_some_and(|k| k.starts_with('@'))
|
||||
&& event.state_key() != Some(event.sender().as_str())
|
||||
{
|
||||
return false; // permission required to post in this room
|
||||
|
Loading…
x
Reference in New Issue
Block a user