pushRuleState property

PushRuleState get pushRuleState

Returns the PushRuleState for this room, based on the m.push_rules stored in the account_data.

Implementation

PushRuleState get pushRuleState {
  final globalPushRules = client.globalPushRules;
  if (globalPushRules == null) {
    // We have no push rules specified at all so we fallback to just notify:
    return PushRuleState.notify;
  }

  final overridePushRules = globalPushRules.override;
  if (overridePushRules != null) {
    for (final pushRule in overridePushRules) {
      if (pushRule.ruleId == id) {
        // "dont_notify" and "coalesce" should be ignored in actions since
        // https://spec.matrix.org/v1.7/client-server-api/#actions
        pushRule.actions
          ..remove('dont_notify')
          ..remove('coalesce');
        if (pushRule.actions.isEmpty) {
          return PushRuleState.dontNotify;
        }
        break;
      }
    }
  }

  final roomPushRules = globalPushRules.room;
  if (roomPushRules != null) {
    for (final pushRule in roomPushRules) {
      if (pushRule.ruleId == id) {
        // "dont_notify" and "coalesce" should be ignored in actions since
        // https://spec.matrix.org/v1.7/client-server-api/#actions
        pushRule.actions
          ..remove('dont_notify')
          ..remove('coalesce');
        if (pushRule.actions.isEmpty) {
          return PushRuleState.mentionsOnly;
        }
        break;
      }
    }
  }

  return PushRuleState.notify;
}