mapToNotificationEvent static method
NotificationEvent
mapToNotificationEvent(
{ - required dynamic data,
- required String notificationEventType,
- required String origin,
- dynamic includeRaw = false,
})
Implementation
static NotificationEvent mapToNotificationEvent(
{required dynamic data,
required String notificationEventType,
required String origin,
includeRaw = false}) {
final notificationType = NOTIFICATION_TYPE_MAP.keys.firstWhere(
(key) => NOTIFICATION_TYPE_MAP[key] == data['payload']['data']['type'],
orElse: () => 'BROADCAST',
);
List<String> recipients;
if (data['payload']['recipients'] is List) {
recipients = List<String>.from(data['payload']['recipients']);
} else if (data['payload']['recipients'] is String) {
recipients = [data['payload']['recipients']];
} else {
recipients = data['payload']['recipients'].keys.toList();
}
final notificationEvent = NotificationEvent(
event: notificationEventType,
origin: origin,
timestamp: data['epoch'].toString(),
from: data['sender'],
to: recipients,
notifID: data['payload_id'].toString(),
channel: NotificationChannel(
name: data['payload']['data']['app'],
icon: data['payload']['data']['icon'],
url: data['payload']['data']['url'],
),
meta: NotificationMeta(
type: 'NOTIFICATION.$notificationType',
),
message: NotificationMessage(
notification: NotificationContent(
title: data['payload']['notification']['title'],
body: data['payload']['notification']['body'],
),
payload: NotificationPayload(
title: data['payload']['data']['asub'],
body: data['payload']['data']['amsg'],
cta: data['payload']['data']['acta'],
embed: data['payload']['data']['aimg'],
meta: NotificationPayloadMeta(
domain: data['payload']['data']['additionalMeta']['domain'] ??
'push.org',
type: data['payload']['data']['additionalMeta']['type'],
data: data['payload']['data']['additionalMeta']['data'],
),
),
),
config: NotificationConfig(
expiry: data['payload']['data']['etime'],
silent: data['payload']['data']['silent'] == '1',
hidden: data['payload']['data']['hidden'] == '1',
),
source: data['source'],
raw: includeRaw
? NotificationRawData(
verificationProof: data['payload']['verificationProof'],
)
: null,
);
return notificationEvent;
}