• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Floating-Dartists / matomo-tracker / 6454971306

09 Oct 2023 09:47AM UTC coverage: 93.108%. First build
6454971306

Pull #122

github

web-flow
Merge 529900ea8 into eec76315c
Pull Request #122: Bump package_info_plus from 4.1.0 to 5.0.0

743 of 798 relevant lines covered (93.11%)

2.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/lib/src/dispatch_settings.dart
1
bool _whereNotOlderThanADay(Map<String, String> action) =>
1✔
2
    DispatchSettings.whereNotOlderThan(
1✔
3
      const Duration(
4
        hours: 23,
5
        minutes: 59,
6
        seconds: 59,
7
      ),
8
    )(action);
1✔
9

10
bool _notOlderThan(
1✔
11
  Map<String, String> action,
12
  DateTime now,
13
  Duration duration,
14
) {
15
  if (action['cdt'] case final date?) {
1✔
16
    return now.difference(DateTime.parse(date)) <= duration;
3✔
17
  }
18
  return false;
19
}
20

21
bool _takeAll(Map<String, String> action) => true;
2✔
22

23
bool _dropAll(Map<String, String> action) => false;
2✔
24

25
/// Used to filter out unwanted actions of the last session if using
26
/// [DispatchSettings.persistent].
27
///
28
/// Will invoked with the serialized `action` and should return `true` if the
29
/// action is still valid, or `false` if the action should be dropped.
30
///
31
/// Filters can be chained using [DispatchSettings.chain].
32
///
33
/// Some build in filters are [DispatchSettings.takeAll],
34
/// [DispatchSettings.dropAll], [DispatchSettings.whereUserId],
35
/// [DispatchSettings.whereNotOlderThan] and
36
/// [DispatchSettings.whereNotOlderThanADay].
37
typedef PersistenceFilter = bool Function(Map<String, String> action);
38

39
/// Controls the behaviour of dispatching actions to Matomo.
40
class DispatchSettings {
41
  /// Uses a persistent dispatch queue.
42
  ///
43
  /// This means that if the app terminates while there are still undispatched
44
  /// actions, those actions are dispatched on next app launch.
45
  ///
46
  /// The [onLoad] can be used to filter the stored actions and drop outdated
47
  /// ones. By default, only actions that are younger then a day are retained.
48
  /// See [PersistenceFilter] for some build in filters.
49
  const DispatchSettings.persistent({
2✔
50
    Duration dequeueInterval = defaultDequeueInterval,
51
    PersistenceFilter onLoad = whereNotOlderThanADay,
52
  }) : this._(
×
53
          dequeueInterval,
54
          true,
55
          onLoad,
56
        );
57

58
  /// Uses a non persistent dispatch queue.
59
  ///
60
  /// This means that if the app terminates while there are still undispatched
61
  /// actions, those actions are lost.
62
  const DispatchSettings.nonPersistent({
24✔
63
    Duration dequeueInterval = defaultDequeueInterval,
64
  }) : this._(
×
65
          dequeueInterval,
66
          false,
67
          null,
68
        );
69

70
  const DispatchSettings._(
24✔
71
    this.dequeueInterval,
72
    this.persistentQueue,
73
    this.onLoad,
74
  );
75

76
  /// The default duration between dispatching actions to the Matomo backend.
77
  static const Duration defaultDequeueInterval = Duration(
78
    seconds: 10,
79
  );
80

81
  /// Takes all actions.
82
  static const PersistenceFilter takeAll = _takeAll;
83

84
  /// Drops all actions.
85
  static const PersistenceFilter dropAll = _dropAll;
86

87
  /// Only takes actions where the userId is `uid`.
88
  static PersistenceFilter whereUserId(String uid) {
1✔
89
    return (Map<String, String> action) => action['uid'] == uid;
3✔
90
  }
91

92
  /// Only takes actions that are not older than `duration`.
93
  static PersistenceFilter whereNotOlderThan(Duration duration) =>
1✔
94
      (Map<String, String> action) => _notOlderThan(
2✔
95
            action,
96
            DateTime.now(),
1✔
97
            duration,
98
          );
99

100
  /// Shorthand for [whereNotOlderThan] with a duration of a day.
101
  static const PersistenceFilter whereNotOlderThanADay = _whereNotOlderThanADay;
102

103
  /// Combines multiple [PersistenceFilter]s.
104
  ///
105
  /// The returned filter is eager, which means that it will return `false`
106
  /// immediately and not check the reaming filters once a filter returned
107
  /// `false`.
108
  static PersistenceFilter chain(Iterable<PersistenceFilter> filters) {
1✔
109
    return filters.fold(takeAll, (previousValue, element) {
2✔
110
      return (Map<String, String> action) {
1✔
111
        if (previousValue(action)) {
1✔
112
          return element(action);
1✔
113
        } else {
114
          return false;
115
        }
116
      };
117
    });
118
  }
119

120
  /// How often to dispatch actions to the Matomo backend.
121
  final Duration dequeueInterval;
122

123
  /// Wheter to store actions persistently before dispatching.
124
  final bool persistentQueue;
125

126
  /// Used to determine which of the stored actions are still valid.
127
  ///
128
  /// Will not be `null` if [persistentQueue] is `true`, or `null` if `false`.
129
  final PersistenceFilter? onLoad;
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc