Line data Source code
1 : import 'package:at_client/src/response/at_notification.dart';
2 : import 'package:at_client/src/response/default_response_parser.dart';
3 : import 'package:at_client/src/response/json_utils.dart';
4 : import 'package:at_client/src/response/response.dart';
5 :
6 : class NotificationResponseParser extends DefaultResponseParser {
7 0 : List<AtNotification> getAtNotifications(Response response) {
8 0 : final notificationList = <AtNotification>[];
9 0 : if (response.isError) {
10 0 : return [];
11 : }
12 0 : final notificationJson = response.response;
13 0 : var notifications = notificationJson.split('notification: ');
14 0 : for (var notification in notifications) {
15 0 : if (notification.isEmpty) {
16 : continue;
17 : }
18 0 : notification = notification.replaceFirst('notification:', '');
19 0 : notification = notification.trim();
20 : final atNotification =
21 0 : AtNotification.fromJson(JsonUtils.decodeJson(notification));
22 0 : notificationList.add(atNotification);
23 : }
24 : return notificationList;
25 : }
26 : }
|