LCOV - code coverage report
Current view: top level - lib/matrix_api_lite/model - matrix_event.dart (source / functions) Coverage Total Hit
Test: merged.info Lines: 95.8 % 24 23
Test Date: 2025-01-14 13:39:53 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           36 :   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           36 :   MatrixEvent.fromJson(super.json)
      49           36 :       : eventId = json['event_id'] as String,
      50           36 :         roomId = json['room_id'] as String?,
      51           36 :         originServerTs = DateTime.fromMillisecondsSinceEpoch(
      52           36 :           json['origin_server_ts'] as int,
      53              :         ),
      54           69 :         unsigned = (json['unsigned'] as Map<String, Object?>?)?.copy(),
      55           69 :         prevContent = (json['prev_content'] as Map<String, Object?>?)?.copy(),
      56           36 :         redacts = json['redacts'] as String?,
      57           36 :         super.fromJson();
      58              : 
      59           34 :   @override
      60              :   Map<String, Object?> toJson() {
      61           34 :     final data = super.toJson();
      62           68 :     data['event_id'] = eventId;
      63          102 :     data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch;
      64           34 :     if (unsigned != null) {
      65           66 :       data['unsigned'] = unsigned;
      66              :     }
      67           34 :     if (prevContent != null) {
      68           66 :       data['prev_content'] = prevContent;
      69              :     }
      70           34 :     if (roomId != null) {
      71           66 :       data['room_id'] = roomId;
      72              :     }
      73           34 :     if (data['state_key'] == null) {
      74           34 :       data.remove('state_key');
      75              :     }
      76           34 :     if (redacts != null) {
      77            0 :       data['redacts'] = redacts;
      78              :     }
      79              :     return data;
      80              :   }
      81              : }
        

Generated by: LCOV version 2.0-1