-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathat_notification.dart
88 lines (78 loc) · 2.84 KB
/
at_notification.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import 'dart:convert';
import 'package:at_client/at_client.dart';
class AtNotification {
late String id;
String key = '';
String from = '';
String to = '';
int epochMillis = 0;
String status = '';
String? value;
String? operation;
String? messageType;
bool? isEncrypted;
int? expiresAtInEpochMillis;
Metadata? metadata;
/// AtNotification instance is created without initializing the fields
AtNotification.empty();
AtNotification(this.id, this.key, this.from, this.to, this.epochMillis,
this.messageType, this.isEncrypted,
{this.value, this.operation, this.expiresAtInEpochMillis, this.metadata});
factory AtNotification.fromJson(Map<String, dynamic> json) {
Metadata? metadata;
if (json['metadata'] != null) {
metadata = Metadata();
metadata.encKeyName = json['metadata'][AtConstants.encryptingKeyName];
metadata.encAlgo = json['metadata'][AtConstants.encryptingAlgo];
metadata.ivNonce = json['metadata'][AtConstants.ivOrNonce];
metadata.skeEncKeyName =
json['metadata'][AtConstants.sharedKeyEncryptedEncryptingKeyName];
metadata.skeEncAlgo =
json['metadata'][AtConstants.sharedKeyEncryptedEncryptingAlgo];
metadata.sharedKeyEnc = json['metadata'][AtConstants.sharedKeyEncrypted];
// AtContants.sharedWithPublicKeyHash will be sent by the server starting v3.0.52
// Notifications received from Secondary server before 3.0.52 does not contain
// AtConstants.sharedWithPublicKeyHash. Therefore, check for null.
if (json['metadata'][AtConstants.sharedWithPublicKeyHash] != null) {
var publicKeyHash =
jsonDecode(json['metadata'][AtConstants.sharedWithPublicKeyHash]);
metadata.pubKeyHash =
PublicKeyHash(publicKeyHash['hash'], publicKeyHash['hashingAlgo']);
}
}
return AtNotification(json['id'], json['key'], json['from'], json['to'],
json['epochMillis'], json['messageType'], json[AtConstants.isEncrypted],
value: json['value'],
operation: json['operation'],
expiresAtInEpochMillis: json['expiresAt'],
metadata: metadata);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'key': key,
'from': from,
'to': to,
'epochMillis': epochMillis,
'value': value,
'operation': operation,
'messageType': messageType,
AtConstants.isEncrypted: isEncrypted,
'notificationStatus': status,
'expiresAt': expiresAtInEpochMillis,
'metadata': metadata
};
}
static List<AtNotification> fromJsonList(
List<Map<String, dynamic>> jsonList) {
final notificationList = <AtNotification>[];
for (var json in jsonList) {
notificationList.add(AtNotification.fromJson(json));
}
return notificationList;
}
@override
String toString() {
return toJson().toString();
}
}