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