MOBILE-2957 fcm: Log notification open if foreground
parent
7a466aac22
commit
c43d0e5820
|
@ -292,6 +292,29 @@ export class CorePushNotificationsProvider {
|
|||
return this.getAddonBadge(siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a firebase event.
|
||||
*
|
||||
* @param {string} name Name of the event.
|
||||
* @param {any} data Data of the event.
|
||||
* @param {boolean} [filter] Whether to filter the data. This is useful when logging a full notification.
|
||||
* @return {Promise<any>} Promise resolved when done. This promise is never rejected.
|
||||
*/
|
||||
logEvent(name: string, data: any, filter?: boolean): Promise<any> {
|
||||
const win = <any> window; // This feature is only present in our fork of the plugin.
|
||||
|
||||
if (win.PushNotification && win.PushNotification.logEvent) {
|
||||
return new Promise((resolve, reject): void => {
|
||||
win.PushNotification.logEvent(resolve, (error) => {
|
||||
this.logger.error('Error logging firebase event', name, error);
|
||||
resolve();
|
||||
}, name, data, !!filter);
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when a push notification is clicked. Redirect the user to the right state.
|
||||
*
|
||||
|
|
|
@ -80,8 +80,12 @@ export class CorePushNotificationsModule {
|
|||
});
|
||||
|
||||
// Listen for local notification clicks (generated by the app).
|
||||
localNotificationsProvider.registerClick(CorePushNotificationsProvider.COMPONENT,
|
||||
pushNotificationsProvider.notificationClicked.bind(pushNotificationsProvider));
|
||||
localNotificationsProvider.registerClick(CorePushNotificationsProvider.COMPONENT, (notification: any) => {
|
||||
// Log notification open event.
|
||||
pushNotificationsProvider.logEvent('moodle_notification_open', notification, true);
|
||||
|
||||
pushNotificationsProvider.notificationClicked(notification);
|
||||
});
|
||||
|
||||
// Allow migrating the table from the old app to the new schema.
|
||||
updateManager.registerAppTableMigration({
|
||||
|
|
Loading…
Reference in New Issue