PushruleEvaluator.fromRuleset constructor

PushruleEvaluator.fromRuleset(
  1. PushRuleSet ruleset
)

Implementation

PushruleEvaluator.fromRuleset(PushRuleSet ruleset) {
  for (final o in ruleset.override ?? []) {
    if (!o.enabled) continue;
    try {
      _override.add(_OptimizedRules.fromRule(o));
    } catch (e) {
      Logs().d('Error parsing push rule $o', e);
    }
  }
  for (final u in ruleset.underride ?? []) {
    if (!u.enabled) continue;
    try {
      _underride.add(_OptimizedRules.fromRule(u));
    } catch (e) {
      Logs().d('Error parsing push rule $u', e);
    }
  }
  for (final c in ruleset.content ?? []) {
    if (!c.enabled) continue;
    final rule = PushRule(
      actions: c.actions,
      conditions: [
        PushCondition(
            kind: 'event_match', key: 'content.body', pattern: c.pattern)
      ],
      ruleId: c.ruleId,
      default$: c.default$,
      enabled: c.enabled,
    );
    try {
      _content_rules.add(_OptimizedRules.fromRule(rule));
    } catch (e) {
      Logs().d('Error parsing push rule $rule', e);
    }
  }
  for (final r in ruleset.room ?? []) {
    if (r.enabled) {
      _room_rules[r.ruleId] = EvaluatedPushRuleAction.fromActions(r.actions);
    }
  }
  for (final r in ruleset.sender ?? []) {
    if (r.enabled) {
      _sender_rules[r.ruleId] =
          EvaluatedPushRuleAction.fromActions(r.actions);
    }
  }
}