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 33 : MatrixEvent.fromJson(super.json)
49 33 : : eventId = json['event_id'] as String,
50 33 : roomId = json['room_id'] as String?,
51 33 : originServerTs = DateTime.fromMillisecondsSinceEpoch(
52 33 : json['origin_server_ts'] as int,
53 : ),
54 66 : unsigned = (json['unsigned'] as Map<String, Object?>?)?.copy(),
55 66 : prevContent = (json['prev_content'] as Map<String, Object?>?)?.copy(),
56 33 : redacts = json['redacts'] as String?,
57 33 : super.fromJson();
58 :
59 33 : @override
60 : Map<String, Object?> toJson() {
61 33 : final data = super.toJson();
62 66 : data['event_id'] = eventId;
63 99 : data['origin_server_ts'] = originServerTs.millisecondsSinceEpoch;
64 33 : if (unsigned != null) {
65 66 : data['unsigned'] = unsigned;
66 : }
67 33 : if (prevContent != null) {
68 66 : data['prev_content'] = prevContent;
69 : }
70 33 : if (roomId != null) {
71 66 : data['room_id'] = roomId;
72 : }
73 33 : if (data['state_key'] == null) {
74 33 : data.remove('state_key');
75 : }
76 33 : if (redacts != null) {
77 0 : data['redacts'] = redacts;
78 : }
79 : return data;
80 : }
81 : }
|