diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index 28bbc77f8..de508f430 100644 --- a/src/core/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -318,13 +318,14 @@ export class CorePushNotificationsProvider { // If the app is in foreground when the notification is received, it's not shown. Let's show it ourselves. if (this.localNotificationsProvider.isAvailable()) { const localNotif: ILocalNotification = { - id: 1, + id: data.notId || 1, data: data, title: '', text: '', channel: 'PushPluginChannel' }, - promises = []; + promises = [], + extraFeatures = this.utils.isTrueOrOne(data.extrafeatures); // Apply formatText to title and message. promises.push(this.textUtils.formatText(notification.title, true, true).then((formattedTitle) => { @@ -333,21 +334,33 @@ export class CorePushNotificationsProvider { localNotif.title = notification.title; })); - promises.push(this.textUtils.formatText(notification.message, true, true).then((formattedMessage) => { - localNotif.text = formattedMessage; - }).catch(() => { - localNotif.text = notification.message; + promises.push(this.textUtils.formatText(notification.message, true, true).catch(() => { + // Error formatting, use the original message. + return notification.message; + }).then((formattedMessage) => { + if (extraFeatures && this.utils.isFalseOrZero(data.notif)) { + // It's a message, use messaging style. Ionic Native doesn't specify this option. + ( localNotif).text = [ + { + message: formattedMessage, + person: data.conversationtype == 2 ? data.userfromfullname : '' + } + ]; + } else { + localNotif.text = formattedMessage; + } })); - if (this.utils.isTrueOrOne(data.extrafeatures)) { - // Extra features enabled. + if (extraFeatures) { + // Use a different icon if needed. localNotif.icon = notification.image; // This feature isn't supported by the official plugin, we use a fork. ( localNotif).iconType = data['image-type']; } Promise.all(promises).then(() => { - this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site); + this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site, + true); }); } diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts index de8e89e94..036803306 100644 --- a/src/providers/local-notifications.ts +++ b/src/providers/local-notifications.ts @@ -470,10 +470,19 @@ export class CoreLocalNotificationsProvider { * be unique inside its component and site. * @param {string} component Component triggering the notification. It is used to generate unique IDs. * @param {string} siteId Site ID. + * @param {boolean} [alreadyUnique] Whether the ID is already unique. * @return {Promise} Promise resolved when the notification is scheduled. */ - schedule(notification: ILocalNotification, component: string, siteId: string): Promise { - return this.getUniqueNotificationId(notification.id, component, siteId).then((uniqueId) => { + schedule(notification: ILocalNotification, component: string, siteId: string, alreadyUnique?: boolean): Promise { + let promise; + + if (alreadyUnique) { + promise = Promise.resolve(notification.id); + } else { + promise = this.getUniqueNotificationId(notification.id, component, siteId); + } + + return promise.then((uniqueId) => { notification.id = uniqueId; notification.data = notification.data || {}; notification.data.component = component;