MOBILE-2961 push: Group push notifications in foreground
parent
b0c33b1526
commit
7723648638
|
@ -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 the app is in foreground when the notification is received, it's not shown. Let's show it ourselves.
|
||||||
if (this.localNotificationsProvider.isAvailable()) {
|
if (this.localNotificationsProvider.isAvailable()) {
|
||||||
const localNotif: ILocalNotification = {
|
const localNotif: ILocalNotification = {
|
||||||
id: 1,
|
id: data.notId || 1,
|
||||||
data: data,
|
data: data,
|
||||||
title: '',
|
title: '',
|
||||||
text: '',
|
text: '',
|
||||||
channel: 'PushPluginChannel'
|
channel: 'PushPluginChannel'
|
||||||
},
|
},
|
||||||
promises = [];
|
promises = [],
|
||||||
|
extraFeatures = this.utils.isTrueOrOne(data.extrafeatures);
|
||||||
|
|
||||||
// Apply formatText to title and message.
|
// Apply formatText to title and message.
|
||||||
promises.push(this.textUtils.formatText(notification.title, true, true).then((formattedTitle) => {
|
promises.push(this.textUtils.formatText(notification.title, true, true).then((formattedTitle) => {
|
||||||
|
@ -333,21 +334,33 @@ export class CorePushNotificationsProvider {
|
||||||
localNotif.title = notification.title;
|
localNotif.title = notification.title;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
promises.push(this.textUtils.formatText(notification.message, true, true).then((formattedMessage) => {
|
promises.push(this.textUtils.formatText(notification.message, true, true).catch(() => {
|
||||||
localNotif.text = formattedMessage;
|
// Error formatting, use the original message.
|
||||||
}).catch(() => {
|
return notification.message;
|
||||||
localNotif.text = 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.
|
||||||
|
(<any> localNotif).text = [
|
||||||
|
{
|
||||||
|
message: formattedMessage,
|
||||||
|
person: data.conversationtype == 2 ? data.userfromfullname : ''
|
||||||
|
}
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
localNotif.text = formattedMessage;
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (this.utils.isTrueOrOne(data.extrafeatures)) {
|
if (extraFeatures) {
|
||||||
// Extra features enabled.
|
// Use a different icon if needed.
|
||||||
localNotif.icon = notification.image;
|
localNotif.icon = notification.image;
|
||||||
// This feature isn't supported by the official plugin, we use a fork.
|
// This feature isn't supported by the official plugin, we use a fork.
|
||||||
(<any> localNotif).iconType = data['image-type'];
|
(<any> localNotif).iconType = data['image-type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site);
|
this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site,
|
||||||
|
true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -470,10 +470,19 @@ export class CoreLocalNotificationsProvider {
|
||||||
* be unique inside its component and site.
|
* be unique inside its component and site.
|
||||||
* @param {string} component Component triggering the notification. It is used to generate unique IDs.
|
* @param {string} component Component triggering the notification. It is used to generate unique IDs.
|
||||||
* @param {string} siteId Site ID.
|
* @param {string} siteId Site ID.
|
||||||
|
* @param {boolean} [alreadyUnique] Whether the ID is already unique.
|
||||||
* @return {Promise<any>} Promise resolved when the notification is scheduled.
|
* @return {Promise<any>} Promise resolved when the notification is scheduled.
|
||||||
*/
|
*/
|
||||||
schedule(notification: ILocalNotification, component: string, siteId: string): Promise<any> {
|
schedule(notification: ILocalNotification, component: string, siteId: string, alreadyUnique?: boolean): Promise<any> {
|
||||||
return this.getUniqueNotificationId(notification.id, component, siteId).then((uniqueId) => {
|
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.id = uniqueId;
|
||||||
notification.data = notification.data || {};
|
notification.data = notification.data || {};
|
||||||
notification.data.component = component;
|
notification.data.component = component;
|
||||||
|
|
Loading…
Reference in New Issue