|
|
|
@ -1,13 +1,26 @@
|
|
|
|
|
import 'package:json_annotation/json_annotation.dart'; |
|
|
|
|
import 'package:meta/meta.dart'; |
|
|
|
|
import 'package:nextcloud/notifications.dart' show DecryptedSubject; |
|
|
|
|
import 'package:nextcloud/notifications.dart' as notifications; |
|
|
|
|
|
|
|
|
|
part 'push_notification.g.dart'; |
|
|
|
|
|
|
|
|
|
/// The json key for [PushNotification.accountID]. |
|
|
|
|
const String _accountIDKey = 'accountID'; |
|
|
|
|
|
|
|
|
|
/// The json key for [PushNotification.priority]. |
|
|
|
|
const String _priorityKey = 'priority'; |
|
|
|
|
|
|
|
|
|
/// The json key for [PushNotification.type]. |
|
|
|
|
const String _typeKey = 'type'; |
|
|
|
|
|
|
|
|
|
/// The json key for [PushNotification.subject]. |
|
|
|
|
const String _subjectKey = 'subject'; |
|
|
|
|
|
|
|
|
|
/// Data for a push notification. |
|
|
|
|
@JsonSerializable() |
|
|
|
|
@immutable |
|
|
|
|
@internal |
|
|
|
|
class PushNotification { |
|
|
|
|
/// Creates a new push notification. |
|
|
|
|
const PushNotification({ |
|
|
|
|
required this.accountID, |
|
|
|
|
required this.priority, |
|
|
|
@ -15,14 +28,44 @@ class PushNotification {
|
|
|
|
|
required this.subject, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/// Creates a new PushNotification object from the given [json] data. |
|
|
|
|
/// |
|
|
|
|
/// Use [PushNotification.fromEncrypted] when you the [subject] is still encrypted. |
|
|
|
|
factory PushNotification.fromJson(final Map<String, dynamic> json) => _$PushNotificationFromJson(json); |
|
|
|
|
|
|
|
|
|
/// Creates a new PushNotification object from the given [json] data containing an encrypted [subject]. |
|
|
|
|
/// |
|
|
|
|
/// Use [PushNotification.fromJson] when the [subject] is not encrypted. |
|
|
|
|
factory PushNotification.fromEncrypted( |
|
|
|
|
final Map<String, dynamic> json, |
|
|
|
|
final notifications.RSAPrivateKey privateKey, |
|
|
|
|
) { |
|
|
|
|
final subject = notifications.decryptPushNotificationSubject(privateKey, json[_subjectKey] as String); |
|
|
|
|
|
|
|
|
|
return PushNotification( |
|
|
|
|
accountID: json[_accountIDKey] as String, |
|
|
|
|
priority: json[_priorityKey] as String, |
|
|
|
|
type: json[_typeKey] as String, |
|
|
|
|
subject: subject, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Parses this object into a json like map. |
|
|
|
|
Map<String, dynamic> toJson() => _$PushNotificationToJson(this); |
|
|
|
|
|
|
|
|
|
/// The account associated to this notification. |
|
|
|
|
@JsonKey(name: _accountIDKey) |
|
|
|
|
final String accountID; |
|
|
|
|
|
|
|
|
|
/// The priority of the notification. |
|
|
|
|
@JsonKey(name: _priorityKey) |
|
|
|
|
final String priority; |
|
|
|
|
|
|
|
|
|
/// The type of the notification. |
|
|
|
|
@JsonKey(name: _typeKey) |
|
|
|
|
final String type; |
|
|
|
|
|
|
|
|
|
final DecryptedSubject subject; |
|
|
|
|
/// The subject of this notification. |
|
|
|
|
@JsonKey(name: _subjectKey) |
|
|
|
|
final notifications.DecryptedSubject subject; |
|
|
|
|
} |
|
|
|
|