|
@@ -1,109 +1,113 @@
|
|
|
import 'notification.m.dart';
|
|
|
|
|
|
typedef _ModelBuilder<T> = T Function(Map<String, dynamic> map);
|
|
|
+
|
|
|
class NotificationDecoder {
|
|
|
- NotificationDecoder._();
|
|
|
+ NotificationDecoder._();
|
|
|
|
|
|
- static final _builders = _ModelBuilderCollection();
|
|
|
+ static final _builders = _ModelBuilderCollection();
|
|
|
|
|
|
- static T decode<T>(Map<String, dynamic> map) {
|
|
|
- final type = decodeType(map);
|
|
|
- final builder = _builders.find(type);
|
|
|
- final model = builder.call(map) as T;
|
|
|
- return model;
|
|
|
- }
|
|
|
- static NotificationTypeEnum decodeType(Map<String, dynamic> map) {
|
|
|
- final typeInt = map['notificationType'] as int;
|
|
|
- return NotificationTypeEnum.values[typeInt];
|
|
|
- }
|
|
|
+ static T decode<T>(Map<String, dynamic> map) {
|
|
|
+ final type = decodeType(map);
|
|
|
+ final builder = _builders.find(type);
|
|
|
+ final model = builder.call(map) as T;
|
|
|
+ return model;
|
|
|
+ }
|
|
|
|
|
|
- static void setup() {
|
|
|
-
|
|
|
- _builders.add(NotificationTypeEnum.ChatMsgNotification,
|
|
|
- (map) => ChatMsgNotification.fromJson(map));
|
|
|
+ static NotificationTypeEnum decodeType(Map<String, dynamic> map) {
|
|
|
+ final typeInt = map['NotificationType'] as int;
|
|
|
+ return NotificationTypeEnum.values[typeInt];
|
|
|
+ }
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.ConnectionNotification,
|
|
|
- (map) => ConnectionNotification.fromJson(map));
|
|
|
+ static void setup() {
|
|
|
+
|
|
|
+ _builders.add(NotificationTypeEnum.ChatMsgNotification,
|
|
|
+ (map) => ChatMsgNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.DisconnectNotification,
|
|
|
- (map) => DisconnectNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.ConnectionNotification,
|
|
|
+ (map) => ConnectionNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.ExamRecordsFinishedNotification,
|
|
|
- (map) => ExamRecordsFinishedNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.DisconnectNotification,
|
|
|
+ (map) => DisconnectNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.PasswordExpiredWarningNotification,
|
|
|
- (map) => PasswordExpiredWarningNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.ExamRecordsFinishedNotification,
|
|
|
+ (map) => ExamRecordsFinishedNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.TokenReplacedNotification,
|
|
|
- (map) => TokenReplacedNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.PasswordExpiredWarningNotification,
|
|
|
+ (map) => PasswordExpiredWarningNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.ApplyConsultationNotification,
|
|
|
- (map) => ApplyConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.TokenReplacedNotification,
|
|
|
+ (map) => TokenReplacedNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.ApprovalApplyConsultationNotification,
|
|
|
- (map) => ApprovalApplyConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.ApplyConsultationNotification,
|
|
|
+ (map) => ApplyConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.ConsultationRemindNotification,
|
|
|
- (map) => ConsultationRemindNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.ApprovalApplyConsultationNotification,
|
|
|
+ (map) => ApprovalApplyConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.InviteeApproveApplyConsultationNotification,
|
|
|
- (map) => InviteeApproveApplyConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.ConsultationRemindNotification,
|
|
|
+ (map) => ConsultationRemindNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.InviteeConsultationNotification,
|
|
|
- (map) => InviteeConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(
|
|
|
+ NotificationTypeEnum.InviteeApproveApplyConsultationNotification,
|
|
|
+ (map) => InviteeApproveApplyConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.InviteeRejectApplyConsultationNotification,
|
|
|
- (map) => InviteeRejectApplyConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.InviteeConsultationNotification,
|
|
|
+ (map) => InviteeConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.RejectApplyConsultationNotification,
|
|
|
- (map) => RejectApplyConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(
|
|
|
+ NotificationTypeEnum.InviteeRejectApplyConsultationNotification,
|
|
|
+ (map) => InviteeRejectApplyConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.AcceptLiveConsultationNotification,
|
|
|
- (map) => AcceptLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.RejectApplyConsultationNotification,
|
|
|
+ (map) => RejectApplyConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.CancelInvitingInLiveConsultationNotification,
|
|
|
- (map) => CancelInvitingInLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.AcceptLiveConsultationNotification,
|
|
|
+ (map) => AcceptLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.CancelLiveConsultationNotification,
|
|
|
- (map) => CancelLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(
|
|
|
+ NotificationTypeEnum.CancelInvitingInLiveConsultationNotification,
|
|
|
+ (map) => CancelInvitingInLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.CloseLiveConsultationNotification,
|
|
|
- (map) => CloseLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.CancelLiveConsultationNotification,
|
|
|
+ (map) => CancelLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.InviteLiveConsultationNotification,
|
|
|
- (map) => InviteLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.CloseLiveConsultationNotification,
|
|
|
+ (map) => CloseLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.InviteInLiveConsultationNotification,
|
|
|
- (map) => InviteInLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.InviteLiveConsultationNotification,
|
|
|
+ (map) => InviteLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.InviteLiveConsultationToDeviceNotification,
|
|
|
- (map) => InviteLiveConsultationToDeviceNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.InviteInLiveConsultationNotification,
|
|
|
+ (map) => InviteInLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.JoinLiveConsultationNotification,
|
|
|
- (map) => JoinLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(
|
|
|
+ NotificationTypeEnum.InviteLiveConsultationToDeviceNotification,
|
|
|
+ (map) => InviteLiveConsultationToDeviceNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.LeaveConsultationNotification,
|
|
|
- (map) => LeaveLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.JoinLiveConsultationNotification,
|
|
|
+ (map) => JoinLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.NetworkErrConsultationNotification,
|
|
|
- (map) => NetworkErrConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.LeaveConsultationNotification,
|
|
|
+ (map) => LeaveLiveConsultationNotification.fromJson(map));
|
|
|
|
|
|
- _builders.add(NotificationTypeEnum.RejectLiveConsultationNotification,
|
|
|
- (map) => RejectLiveConsultationNotification.fromJson(map));
|
|
|
+ _builders.add(NotificationTypeEnum.NetworkErrConsultationNotification,
|
|
|
+ (map) => NetworkErrConsultationNotification.fromJson(map));
|
|
|
|
|
|
- }
|
|
|
+ _builders.add(NotificationTypeEnum.RejectLiveConsultationNotification,
|
|
|
+ (map) => RejectLiveConsultationNotification.fromJson(map));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class _ModelBuilderCollection {
|
|
|
- final Map<NotificationTypeEnum, _ModelBuilder> _source = {};
|
|
|
+ final Map<NotificationTypeEnum, _ModelBuilder> _source = {};
|
|
|
|
|
|
- void add(NotificationTypeEnum type, _ModelBuilder builder) {
|
|
|
- _source[type] = builder;
|
|
|
- }
|
|
|
+ void add(NotificationTypeEnum type, _ModelBuilder builder) {
|
|
|
+ _source[type] = builder;
|
|
|
+ }
|
|
|
|
|
|
- _ModelBuilder find(NotificationTypeEnum type) {
|
|
|
- final builder = _source[type];
|
|
|
- return builder!;
|
|
|
- }
|
|
|
+ _ModelBuilder find(NotificationTypeEnum type) {
|
|
|
+ final builder = _source[type];
|
|
|
+ return builder!;
|
|
|
+ }
|
|
|
}
|
|
|
-
|