notificationdecoder.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import 'notification.m.dart';
  2. typedef _ModelBuilder<T> = T Function(Map<String, dynamic> map);
  3. class NotificationDecoder {
  4. NotificationDecoder._();
  5. static final _builders = _ModelBuilderCollection();
  6. static T decode<T>(Map<String, dynamic> map) {
  7. final type = decodeType(map);
  8. final builder = _builders.find(type);
  9. final model = builder.call(map) as T;
  10. return model;
  11. }
  12. static NotificationTypeEnum decodeType(Map<String, dynamic> map) {
  13. final typeInt = map['NotificationType'] as int;
  14. return NotificationTypeEnum.values[typeInt];
  15. }
  16. static void setup() {
  17. /** Register notification model builders here */
  18. _builders.add(NotificationTypeEnum.ApplyProbeApplicationSettingNotification,
  19. (map) => ApplyProbeApplicationSettingNotification.fromJson(map));
  20. _builders.add(NotificationTypeEnum.SendCommandToDeviceNotification,
  21. (map) => SendCommandToDeviceNotification.fromJson(map));
  22. _builders.add(NotificationTypeEnum.SendResultToClientNotification,
  23. (map) => SendResultToClientNotification.fromJson(map));
  24. _builders.add(NotificationTypeEnum.SystemSettingSaveAndExitToClientNotification,
  25. (map) => SystemSettingSaveAndExitToClientNotification.fromJson(map));
  26. _builders.add(NotificationTypeEnum.AnnouncementPublishNotification,
  27. (map) => AnnouncementNotification.fromJson(map));
  28. _builders.add(NotificationTypeEnum.ChatMsgNotification,
  29. (map) => ChatMsgNotification.fromJson(map));
  30. _builders.add(NotificationTypeEnum.ConnectionNotification,
  31. (map) => ConnectionNotification.fromJson(map));
  32. _builders.add(NotificationTypeEnum.DeviceControlledParametersNotification,
  33. (map) => DeviceControlledParametersNotification.fromJson(map));
  34. _builders.add(NotificationTypeEnum.DeviceDisconnectRemoteControlNotification,
  35. (map) => DeviceDisconnectRemoteControlNotification.fromJson(map));
  36. _builders.add(NotificationTypeEnum.DeviceParametersNotification,
  37. (map) => DeviceParametersNotification.fromJson(map));
  38. _builders.add(NotificationTypeEnum.DeviceRejectRemoteControlNotification,
  39. (map) => DeviceRejectRemoteControlNotification.fromJson(map));
  40. _builders.add(NotificationTypeEnum.DisconnectNotification,
  41. (map) => DisconnectNotification.fromJson(map));
  42. _builders.add(NotificationTypeEnum.ExamRecordsFinishedNotification,
  43. (map) => ExamRecordsFinishedNotification.fromJson(map));
  44. _builders.add(NotificationTypeEnum.ExecuteResultNotification,
  45. (map) => ExecuteResultNotification.fromJson(map));
  46. _builders.add(NotificationTypeEnum.ModifyDeviceMergedVideoSizeNotification,
  47. (map) => ModifyDeviceMergedVideoSizeNotification.fromJson(map));
  48. _builders.add(NotificationTypeEnum.PasswordExpiredWarningNotification,
  49. (map) => PasswordExpiredWarningNotification.fromJson(map));
  50. _builders.add(NotificationTypeEnum.ProgressBarNotification,
  51. (map) => ProgressBarNotification.fromJson(map));
  52. _builders.add(NotificationTypeEnum.TokenReplacedNotification,
  53. (map) => TokenReplacedNotification.fromJson(map));
  54. _builders.add(NotificationTypeEnum.VersionUpgradeNotification,
  55. (map) => UpgradeVersionNotification.fromJson(map));
  56. _builders.add(NotificationTypeEnum.CloseLiveToDeviceNotification,
  57. (map) => CloseLiveToDeviceNotification.fromJson(map));
  58. _builders.add(NotificationTypeEnum.ConnectStatusToClientNotification,
  59. (map) => ConnectStatusToClientNotification.fromJson(map));
  60. _builders.add(NotificationTypeEnum.ConnectStatusToDeviceNotification,
  61. (map) => ConnectStatusToDeviceNotification.fromJson(map));
  62. _builders.add(NotificationTypeEnum.DeviceLiveFinishedNotification,
  63. (map) => DeviceLiveFinishedNotification.fromJson(map));
  64. _builders.add(NotificationTypeEnum.StartLiveToDeviceNotification,
  65. (map) => StartLiveToDeviceNotification.fromJson(map));
  66. _builders.add(NotificationTypeEnum.CancelInvitingInLiveCourseNotification,
  67. (map) => CancelInvitingInLiveCourseNotification.fromJson(map));
  68. _builders.add(NotificationTypeEnum.CancelLiveCourseNotification,
  69. (map) => CancelLiveCourseNotification.fromJson(map));
  70. _builders.add(NotificationTypeEnum.ChangeShareInLiveCourseNotification,
  71. (map) => ChangeShareInLiveCourseNotification.fromJson(map));
  72. _builders.add(NotificationTypeEnum.CloseLiveCourseNotification,
  73. (map) => CloseLiveCourseNotification.fromJson(map));
  74. _builders.add(NotificationTypeEnum.CloseCourseHeartRateToDeviceNotification,
  75. (map) => CloseCourseHeartRateToDeviceNotification.fromJson(map));
  76. _builders.add(NotificationTypeEnum.StartEducationHeartRateToDeviceNotification,
  77. (map) => StartEducationHeartRateToDeviceNotification.fromJson(map));
  78. _builders.add(NotificationTypeEnum.CourcePaySuccessNotification,
  79. (map) => CourcePaySuccessNotification.fromJson(map));
  80. _builders.add(NotificationTypeEnum.CourseEntryNotification,
  81. (map) => CourseEntryNotification.fromJson(map));
  82. _builders.add(NotificationTypeEnum.CourseStatusNotification,
  83. (map) => CourseStatusNotification.fromJson(map));
  84. _builders.add(NotificationTypeEnum.HeartRateJoinCoNotification,
  85. (map) => HeartRateJoinCourseNotification.fromJson(map));
  86. _builders.add(NotificationTypeEnum.HeartRateLeaveCourseNotification,
  87. (map) => HeartRateLeaveCourseNotification.fromJson(map));
  88. _builders.add(NotificationTypeEnum.InviteLiveCourseNotification,
  89. (map) => InviteLiveCourseNotification.fromJson(map));
  90. _builders.add(NotificationTypeEnum.JoinLiveCourseNotification,
  91. (map) => JoinLiveCourseNotification.fromJson(map));
  92. _builders.add(NotificationTypeEnum.DeviceJoinLiveCourseNotification,
  93. (map) => DeviceJoinLiveCourseNotification.fromJson(map));
  94. _builders.add(NotificationTypeEnum.LeaveCoursenNotification,
  95. (map) => LeaveLiveCourseNotification.fromJson(map));
  96. _builders.add(NotificationTypeEnum.MuteLiveCourseNotification,
  97. (map) => MuteLiveCourseNotification.fromJson(map));
  98. _builders.add(NotificationTypeEnum.NetworkErrCourseNotification,
  99. (map) => NetworkErrCourseNotification.fromJson(map));
  100. _builders.add(NotificationTypeEnum.SendLiveInteractiveBoardDataNotification,
  101. (map) => SendLiveInteractiveBoardDataNotification.fromJson(map));
  102. _builders.add(NotificationTypeEnum.SwitchLiveCourseVideoNotification,
  103. (map) => SwitchLiveCourseVideoNotification.fromJson(map));
  104. _builders.add(NotificationTypeEnum.UpgradeNotification,
  105. (map) => UpgradeNotification.fromJson(map));
  106. _builders.add(NotificationTypeEnum.ApplyConsultationNotification,
  107. (map) => ApplyConsultationNotification.fromJson(map));
  108. _builders.add(NotificationTypeEnum.ApprovalApplyConsultationNotification,
  109. (map) => ApprovalApplyConsultationNotification.fromJson(map));
  110. _builders.add(NotificationTypeEnum.CloseConsolutionHeartRateToDeviceNotification,
  111. (map) => CloseConsolutionHeartRateToDeviceNotification.fromJson(map));
  112. _builders.add(NotificationTypeEnum.ConsultationAnswerTimeout,
  113. (map) => ConsultationAnswerTimeoutNotification.fromJson(map));
  114. _builders.add(NotificationTypeEnum.ConsultationRemindNotification,
  115. (map) => ConsultationRemindNotification.fromJson(map));
  116. _builders.add(NotificationTypeEnum.InviteeApproveApplyConsultationNotification,
  117. (map) => InviteeApproveApplyConsultationNotification.fromJson(map));
  118. _builders.add(NotificationTypeEnum.InviteeConsultationNotification,
  119. (map) => InviteeConsultationNotification.fromJson(map));
  120. _builders.add(NotificationTypeEnum.InviteeRejectApplyConsultationNotification,
  121. (map) => InviteeRejectApplyConsultationNotification.fromJson(map));
  122. _builders.add(NotificationTypeEnum.RejectApplyConsultationNotification,
  123. (map) => RejectApplyConsultationNotification.fromJson(map));
  124. _builders.add(NotificationTypeEnum.StartConsolutionHeartRateToDeviceNotification,
  125. (map) => StartConsolutionHeartRateToDeviceNotification.fromJson(map));
  126. _builders.add(NotificationTypeEnum.MeetingMemberNotification,
  127. (map) => MeetingMemberNotification.fromJson(map));
  128. _builders.add(NotificationTypeEnum.MeetingHangupNotification,
  129. (map) => MeetingHangupNotification.fromJson(map));
  130. _builders.add(NotificationTypeEnum.RejectMeetingNotification,
  131. (map) => RejectMeetingNotification.fromJson(map));
  132. _builders.add(NotificationTypeEnum.AcceptMeetingNotification,
  133. (map) => AcceptMeetingNotification.fromJson(map));
  134. _builders.add(NotificationTypeEnum.MeetingPendingMemberTimeoutNotification,
  135. (map) => MeetingPendingMemberTimeoutNotification.fromJson(map));
  136. _builders.add(NotificationTypeEnum.ProbeApplicationSettingResponseNotification,
  137. (map) => ProbeApplicationSettingResponseNotification.fromJson(map));
  138. _builders.add(NotificationTypeEnum.CancelLogDownloadNotification,
  139. (map) => CancelLogDownloadNotification.fromJson(map));
  140. _builders.add(NotificationTypeEnum.DeviceDownloadPatchProgressToUserNotification,
  141. (map) => DeviceDownloadPatchProgressToUserNotification.fromJson(map));
  142. _builders.add(NotificationTypeEnum.DevicePrinterRequestNotification,
  143. (map) => DevicePrinterRequestNotification.fromJson(map));
  144. _builders.add(NotificationTypeEnum.DevicePrinterResultNotification,
  145. (map) => DevicePrinterResultNotification.fromJson(map));
  146. _builders.add(NotificationTypeEnum.GetRemoteLogToClientNotification,
  147. (map) => GetRemoteLogToClientNotification.fromJson(map));
  148. _builders.add(NotificationTypeEnum.GetRemoteLogToDeviceNotification,
  149. (map) => GetRemoteLogToDeviceNotification.fromJson(map));
  150. _builders.add(NotificationTypeEnum.PushDevicePatchToDeviceNotification,
  151. (map) => PushDevicePatchToDeviceNotification.fromJson(map));
  152. _builders.add(NotificationTypeEnum.RestartDeviceNotification,
  153. (map) => RestartDeviceNotification.fromJson(map));
  154. _builders.add(NotificationTypeEnum.AcceptLiveConsultationNotification,
  155. (map) => AcceptLiveConsultationNotification.fromJson(map));
  156. _builders.add(NotificationTypeEnum.CancelInvitingInLiveConsultationNotification,
  157. (map) => CancelInvitingInLiveConsultationNotification.fromJson(map));
  158. _builders.add(NotificationTypeEnum.CancelLiveConsultationNotification,
  159. (map) => CancelLiveConsultationNotification.fromJson(map));
  160. _builders.add(NotificationTypeEnum.CloseLiveConsultationNotification,
  161. (map) => CloseLiveConsultationNotification.fromJson(map));
  162. _builders.add(NotificationTypeEnum.ChangeConsultationNotification,
  163. (map) => ChangeConsultationNotification.fromJson(map));
  164. _builders.add(NotificationTypeEnum.ChangeConsultationToDeviceNotification,
  165. (map) => ChangeConsultationToDeviceNotification.fromJson(map));
  166. _builders.add(NotificationTypeEnum.CloseConsultationDueToChangeNotification,
  167. (map) => CloseConsultationDueToChangeNotification.fromJson(map));
  168. _builders.add(NotificationTypeEnum.EmergencyCallFailedNotification,
  169. (map) => EmergencyCallFailedNotification.fromJson(map));
  170. _builders.add(NotificationTypeEnum.EmergencyCallNotification,
  171. (map) => EmergencyCallNotification.fromJson(map));
  172. _builders.add(NotificationTypeEnum.HeartRateJoinConsultationNotification,
  173. (map) => HeartRateJoinConsultationNotification.fromJson(map));
  174. _builders.add(NotificationTypeEnum.HeartRateLeaveConsultationNotification,
  175. (map) => HeartRateLeaveConsultationNotification.fromJson(map));
  176. _builders.add(NotificationTypeEnum.InviteLiveConsultationNotification,
  177. (map) => InviteLiveConsultationNotification.fromJson(map));
  178. _builders.add(NotificationTypeEnum.InviteInLiveConsultationNotification,
  179. (map) => InviteInLiveConsultationNotification.fromJson(map));
  180. _builders.add(NotificationTypeEnum.JoinInLiveConsultationNotification,
  181. (map) => JoinInLiveConsultationNotification.fromJson(map));
  182. _builders.add(NotificationTypeEnum.RejectInviteLiveConsultationNotification,
  183. (map) => RejectInviteLiveConsultationNotification.fromJson(map));
  184. _builders.add(NotificationTypeEnum.JoinLiveConsultationNotification,
  185. (map) => JoinLiveConsultationNotification.fromJson(map));
  186. _builders.add(NotificationTypeEnum.LeaveConsultationNotification,
  187. (map) => LeaveLiveConsultationNotification.fromJson(map));
  188. _builders.add(NotificationTypeEnum.MuteLiveConsultationNotification,
  189. (map) => MuteLiveConsultationNotification.fromJson(map));
  190. _builders.add(NotificationTypeEnum.NetworkErrConsultationNotification,
  191. (map) => NetworkErrConsultationNotification.fromJson(map));
  192. _builders.add(NotificationTypeEnum.RealtimeConsultationMembersNotification,
  193. (map) => RealtimeConsultationMembersNotification.fromJson(map));
  194. _builders.add(NotificationTypeEnum.RejectLiveConsultationNotification,
  195. (map) => RejectLiveConsultationNotification.fromJson(map));
  196. _builders.add(NotificationTypeEnum.SwitchLiveConsultationVideoNotification,
  197. (map) => SwitchLiveConsultationVideoNotification.fromJson(map));
  198. _builders.add(NotificationTypeEnum.UploadConsultationDataNotification,
  199. (map) => UploadConsultationDataNotification.fromJson(map));
  200. _builders.add(NotificationTypeEnum.SendInteractiveBoardDataNotification,
  201. (map) => SendInteractiveBoardDataNotification.fromJson(map));
  202. }
  203. }
  204. class _ModelBuilderCollection {
  205. final Map<NotificationTypeEnum, _ModelBuilder> _source = {};
  206. void add(NotificationTypeEnum type, _ModelBuilder builder) {
  207. _source[type] = builder;
  208. }
  209. _ModelBuilder find(NotificationTypeEnum type) {
  210. final builder = _source[type];
  211. return builder!;
  212. }
  213. }