LCOV - code coverage report
Current view: top level - lib/src - event_status.dart (source / functions) Hit Total Coverage
Test: merged.info Lines: 11 12 91.7 %
Date: 2024-11-12 07:37:08 Functions: 0 0 -

          Line data    Source code
       1             : /// Defines event status:
       2             : /// - removed
       3             : /// - error: (http request failed)
       4             : /// - sending: (http request started)
       5             : /// - sent: (http request successful)
       6             : /// - synced: (event came from sync loop)
       7             : /// - roomState
       8             : enum EventStatus {
       9             :   error,
      10             :   sending,
      11             :   sent,
      12             :   synced,
      13             :   roomState,
      14             : }
      15             : 
      16             : /// Returns `EventStatusEnum` value from `intValue`.
      17             : ///
      18             : /// - -2 == error;
      19             : /// - -1 == sending;
      20             : /// -  0 == sent;
      21             : /// -  1 == synced;
      22             : /// -  2 == roomState;
      23          36 : EventStatus eventStatusFromInt(int intValue) =>
      24          72 :     EventStatus.values[intValue + 2];
      25             : 
      26             : /// Takes two [EventStatus] values and returns the one with higher
      27             : /// (better in terms of message sending) status.
      28          12 : EventStatus latestEventStatus(EventStatus status1, EventStatus status2) =>
      29          36 :     status1.intValue > status2.intValue ? status1 : status2;
      30             : 
      31             : extension EventStatusExtension on EventStatus {
      32             :   /// Returns int value of the event status.
      33             :   ///
      34             :   /// - -2 == error;
      35             :   /// - -1 == sending;
      36             :   /// -  0 == sent;
      37             :   /// -  1 == synced;
      38             :   /// -  2 == roomState;
      39         108 :   int get intValue => (index - 2);
      40             : 
      41             :   /// Return `true` if the `EventStatus` equals `error`.
      42          68 :   bool get isError => this == EventStatus.error;
      43             : 
      44             :   /// Return `true` if the `EventStatus` equals `sending`.
      45          72 :   bool get isSending => this == EventStatus.sending;
      46             : 
      47             :   /// Return `true` if the `EventStatus` equals `roomState`.
      48           0 :   bool get isRoomState => this == EventStatus.roomState;
      49             : 
      50             :   /// Returns `true` if the status is sent or later:
      51             :   /// [EventStatus.sent], [EventStatus.synced] or [EventStatus.roomState].
      52          68 :   bool get isSent => [
      53             :         EventStatus.sent,
      54             :         EventStatus.synced,
      55             :         EventStatus.roomState,
      56          34 :       ].contains(this);
      57             : 
      58             :   /// Returns `true` if the status is `synced` or `roomState`:
      59             :   /// [EventStatus.synced] or [EventStatus.roomState].
      60          68 :   bool get isSynced => [
      61             :         EventStatus.synced,
      62             :         EventStatus.roomState,
      63          34 :       ].contains(this);
      64             : }

Generated by: LCOV version 1.14