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

          Line data    Source code
       1             : /*
       2             :  *   Famedly Matrix SDK
       3             :  *   Copyright (C) 2020, 2021 Famedly GmbH
       4             :  *
       5             :  *   This program is free software: you can redistribute it and/or modify
       6             :  *   it under the terms of the GNU Affero General Public License as
       7             :  *   published by the Free Software Foundation, either version 3 of the
       8             :  *   License, or (at your option) any later version.
       9             :  *
      10             :  *   This program is distributed in the hope that it will be useful,
      11             :  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      13             :  *   GNU Affero General Public License for more details.
      14             :  *
      15             :  *   You should have received a copy of the GNU Affero General Public License
      16             :  *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
      17             :  */
      18             : 
      19             : import 'package:matrix/matrix.dart';
      20             : 
      21             : /// This extension adds easy-to-use filters for the sync update, meant to be used on the `client.onSync` stream, e.g.
      22             : /// `client.onSync.stream.where((s) => s.hasRoomUpdate)`. Multiple filters can easily be
      23             : /// combind with boolean logic: `client.onSync.stream.where((s) => s.hasRoomUpdate || s.hasPresenceUpdate)`
      24             : extension SyncUpdateFilters on SyncUpdate {
      25             :   /// Returns true if this sync updat has a room update
      26             :   /// That means there is account data, if there is a room in one of the `join`, `leave` or `invite` blocks of the sync or if there is a to_device event.
      27           2 :   bool get hasRoomUpdate {
      28             :     // if we have an account data change we need to re-render, as `m.direct` might have changed
      29           4 :     if (accountData?.isNotEmpty ?? false) {
      30             :       return true;
      31             :     }
      32             :     // check for a to_device event
      33           4 :     if (toDevice?.isNotEmpty ?? false) {
      34             :       return true;
      35             :     }
      36             :     // return if there are rooms to update
      37           6 :     return (rooms?.join?.isNotEmpty ?? false) ||
      38           6 :         (rooms?.invite?.isNotEmpty ?? false) ||
      39           6 :         (rooms?.leave?.isNotEmpty ?? false);
      40             :   }
      41             : 
      42             :   /// Returns if this sync update has presence updates
      43           6 :   bool get hasPresenceUpdate => presence?.isNotEmpty ?? false;
      44             : }

Generated by: LCOV version 1.14