Merge pull request #2588 from dpalou/MOBILE-3523
MOBILE-3523 push: Allow push with siteurl or no sitemain
commit
b66935cb49
|
@ -457,8 +457,19 @@ export class CorePushNotificationsProvider {
|
||||||
*/
|
*/
|
||||||
onMessageReceived(notification: any): void {
|
onMessageReceived(notification: any): void {
|
||||||
const data = notification ? notification.additionalData : {};
|
const data = notification ? notification.additionalData : {};
|
||||||
|
let promise;
|
||||||
|
|
||||||
this.sitesProvider.getSite(data.site).then((site) => {
|
if (data.site) {
|
||||||
|
promise = this.sitesProvider.getSite(data.site);
|
||||||
|
} else if (data.siteurl) {
|
||||||
|
promise = this.sitesProvider.getSiteByUrl(data.siteurl);
|
||||||
|
} else {
|
||||||
|
// Notification not related to any site.
|
||||||
|
promise = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
promise.then((site: CoreSite | undefined) => {
|
||||||
|
data.site = site && site.getId();
|
||||||
|
|
||||||
if (typeof data.customdata == 'string') {
|
if (typeof data.customdata == 'string') {
|
||||||
data.customdata = this.textUtils.parseJSON(data.customdata, {});
|
data.customdata = this.textUtils.parseJSON(data.customdata, {});
|
||||||
|
@ -470,58 +481,22 @@ export class CorePushNotificationsProvider {
|
||||||
const localNotif: ILocalNotification = {
|
const localNotif: ILocalNotification = {
|
||||||
id: data.notId || 1,
|
id: data.notId || 1,
|
||||||
data: data,
|
data: data,
|
||||||
title: '',
|
title: notification.title,
|
||||||
text: '',
|
text: notification.message,
|
||||||
channel: 'PushPluginChannel'
|
channel: 'PushPluginChannel'
|
||||||
},
|
};
|
||||||
options = {
|
const isAndroid = CoreApp.instance.isAndroid();
|
||||||
clean: true,
|
const extraFeatures = this.utils.isTrueOrOne(data.extrafeatures);
|
||||||
singleLine: true,
|
|
||||||
contextLevel: 'system',
|
|
||||||
instanceId: 0,
|
|
||||||
filter: true
|
|
||||||
},
|
|
||||||
isAndroid = CoreApp.instance.isAndroid(),
|
|
||||||
extraFeatures = this.utils.isTrueOrOne(data.extrafeatures);
|
|
||||||
|
|
||||||
// Get the filters to apply to text and message. Don't use FIlterHelper to prevent circular dependencies.
|
|
||||||
this.filterProvider.canGetFilters(site.getId()).then((canGet) => {
|
|
||||||
if (!canGet) {
|
|
||||||
// We cannot check which filters are available, apply them all.
|
|
||||||
return this.filterDelegate.getEnabledFilters(options.contextLevel, options.instanceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.filterProvider.getAvailableInContext(options.contextLevel, options.instanceId, site.getId());
|
|
||||||
}).catch(() => {
|
|
||||||
return [];
|
|
||||||
}).then((filters) => {
|
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
// Apply formatText to title and message.
|
|
||||||
promises.push(this.filterProvider.formatText(notification.title, options, filters, site.getId())
|
|
||||||
.then((title) => {
|
|
||||||
localNotif.title = title;
|
|
||||||
}).catch(() => {
|
|
||||||
localNotif.title = notification.title;
|
|
||||||
}));
|
|
||||||
|
|
||||||
promises.push(this.filterProvider.formatText(notification.message, options, filters, site.getId())
|
|
||||||
.catch(() => {
|
|
||||||
// Error formatting, use the original message.
|
|
||||||
return notification.message;
|
|
||||||
}).then((formattedMessage) => {
|
|
||||||
if (extraFeatures && isAndroid && this.utils.isFalseOrZero(data.notif)) {
|
if (extraFeatures && isAndroid && this.utils.isFalseOrZero(data.notif)) {
|
||||||
// It's a message, use messaging style. Ionic Native doesn't specify this option.
|
// It's a message, use messaging style. Ionic Native doesn't specify this option.
|
||||||
(<any> localNotif).text = [
|
(<any> localNotif).text = [
|
||||||
{
|
{
|
||||||
message: formattedMessage,
|
message: notification.message,
|
||||||
person: data.conversationtype == 2 ? data.userfromfullname : ''
|
person: data.conversationtype == 2 ? data.userfromfullname : ''
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
} else {
|
|
||||||
localNotif.text = formattedMessage;
|
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
|
|
||||||
if (extraFeatures && isAndroid) {
|
if (extraFeatures && isAndroid) {
|
||||||
// Use a different icon if needed.
|
// Use a different icon if needed.
|
||||||
|
@ -536,12 +511,8 @@ export class CorePushNotificationsProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site || '',
|
||||||
this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site,
|
|
||||||
true);
|
true);
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger a notification received event.
|
// Trigger a notification received event.
|
||||||
|
|
|
@ -1306,6 +1306,24 @@ export class CoreSitesProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a site with a certain URL. It will return the first site found.
|
||||||
|
*
|
||||||
|
* @param siteUrl The site URL.
|
||||||
|
* @return Promise resolved with the site.
|
||||||
|
*/
|
||||||
|
async getSiteByUrl(siteUrl: string): Promise<CoreSite> {
|
||||||
|
await this.dbReady;
|
||||||
|
|
||||||
|
const data = await this.appDB.getRecord(CoreSitesProvider.SITES_TABLE, { siteUrl });
|
||||||
|
|
||||||
|
if (typeof this.sites[data.id] != 'undefined') {
|
||||||
|
return this.sites[data.id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.makeSiteFromSiteListEntry(data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a site from an entry of the sites list DB. The new site is added to the list of "cached" sites: this.sites.
|
* Create a site from an entry of the sites list DB. The new site is added to the list of "cached" sites: this.sites.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue