LCOV - code coverage report
Current view: top level - lib/matrix_api_lite/model - matrix_event.dart (source / functions) Hit Total Coverage
Test: merged.info Lines: 23 24 95.8 %
Date: 2024-07-12 20:20:16 Functions: 0 0 -

          Line data    Source code
       1             : /* MIT License
       2             : * 
       3             : * Copyright (C) 2019, 2020, 2021 Famedly GmbH
       4             : * 
       5             : * Permission is hereby granted, free of charge, to any person obtaining a copy
       6             : * of this software and associated documentation files (the "Software"), to deal
       7             : * in the Software without restriction, including without limitation the rights
       8             : * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             : * copies of the Software, and to permit persons to whom the Software is
      10             : * furnished to do so, subject to the following conditions:
      11             : * 
      12             : * The above copyright notice and this permission notice shall be included in all
      13             : * copies or substantial portions of the Software.
      14             : * 
      15             : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             : * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      21             : * SOFTWARE.
      22             : */
      23             : 
      24             : import 'package:matrix/matrix_api_lite/model/stripped_state_event.dart';
      25             : import 'package:matrix/matrix_api_lite/utils/map_copy_extension.dart';
      26             : 
      27             : class MatrixEvent extends StrippedStateEvent {
      28             :   String eventId;
      29             :   String? roomId;
      30             :   DateTime originServerTs;
      31             :   Map<String, Object?>? unsigned;
      32             :   Map<String, Object?>? prevContent;
      33             :   String? redacts;
      34             : 
      35          35 :   MatrixEvent({
      36             :     required super.type,
      37             :     required super.content,
      38             :     required super.senderId,
      39             :     super.stateKey,
      40             :     required this.eventId,
      41             :     this.roomId,
      42             :     required this.originServerTs,
      43             :     this.unsigned,
      44             :     this.prevContent,
      45             :     this.redacts,
      46             :   });
      47             : 
      48          31 :   MatrixEvent.fromJson(super.json)
      49          31 :       : eventId = json['event_id'] as String,
      50          31 :         roomId = json['room_id'] as String?,
      51          31 :         originServerTs = DateTime.fromMillisecondsSinceEpoch(
      52          31 :             json['origin_server_ts'] as int),
      53          62 :         unsigned = (json['unsigned'] as Map<String, Object?>?)?.copy(),
      54          62 :         prevContent = (json['prev_content'] as Map<String, Object?>?)?.copy(),
      55          31 :         redacts = json['redacts'] as String?,
      56          31 :         super.fromJson();
      57             : 
      58          31 :   @override
      59             :   Map<String, Object?> toJson() {
      60          31 :     final data = super.toJson();
      61          62 :     data['event_id'] = eventId;
      62          93 :     data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch;
      63          31 :     if (unsigned != null) {
      64          62 :       data['unsigned'] = unsigned;
      65             :     }
      66          31 :     if (prevContent != null) {
      67          62 :       data['prev_content'] = prevContent;
      68             :     }
      69          31 :     if (roomId != null) {
      70          62 :       data['room_id'] = roomId;
      71             :     }
      72          31 :     if (data['state_key'] == null) {
      73          31 :       data.remove('state_key');
      74             :     }
      75          31 :     if (redacts != null) {
      76           0 :       data['redacts'] = redacts;
      77             :     }
      78             :     return data;
      79             :   }
      80             : }

Generated by: LCOV version 1.14