Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added moenage stuff #1787

Merged
merged 9 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
367 changes: 335 additions & 32 deletions modules/ensemble/lib/action/Log_event_action.dart

Large diffs are not rendered by default.

51 changes: 32 additions & 19 deletions modules/ensemble/lib/framework/notification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class NotificationManager {
return null;
}

bool isMoEngageNotification(RemoteMessage message) {
return message.data['push_from']?.toString().toLowerCase() == 'moengage';
}

void _initListener(
{Future<void> Function(RemoteMessage)? backgroundNotificationHandler}) {
/// listen for token changes and store a copy
Expand All @@ -74,19 +78,25 @@ class NotificationManager {

/// This is when the app is in the foreground
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
Ensemble.externalDataContext.addAll({
'title': message.notification?.title,
'body': message.notification?.body,
'data': message.data
});
// By default, notification won't show on foreground, so we leverage
// local notification to show it in the foreground
await notificationUtils.initNotifications();
notificationUtils.showNotification(
message.notification?.title ?? '',
body: message.notification?.body,
payload: jsonEncode(message.toMap()),
);

if (!isMoEngageNotification(message)) {
// Handle regular FCM notifications as before
Ensemble.externalDataContext.addAll({
'title': message.notification?.title,
'body': message.notification?.body,
'data': message.data
});

// By default, notification won't show on foreground, so we leverage
// local notification to show it in the foreground

await notificationUtils.initNotifications();
notificationUtils.showNotification(
message.notification?.title ?? '',
body: message.notification?.body,
payload: jsonEncode(message.toMap()),
);
}
});

/// when the app is in the background, we can't run UI logic.
Expand All @@ -96,13 +106,16 @@ class NotificationManager {
}

/// This is when the app is in the background and the user taps on the notification

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
Ensemble.externalDataContext.addAll({
'title': message.notification?.title,
'body': message.notification?.body,
'data': message.data
});
handleNotification(jsonEncode(message.toMap()));
if (!isMoEngageNotification(message)) {
Ensemble.externalDataContext.addAll({
'title': message.notification?.title,
'body': message.notification?.body,
'data': message.data
});
handleNotification(jsonEncode(message.toMap()));
}
});
}

Expand Down
Loading