From 258a646f200a9300249939e9ee36ffc798d1c09b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 12 Apr 2019 14:24:26 +0200 Subject: [PATCH 1/4] MOBILE-2961 push: Use push channel in some local notifications --- src/core/pushnotifications/providers/pushnotifications.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index 108f43601..f155eb8be 100644 --- a/src/core/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -321,7 +321,8 @@ export class CorePushNotificationsProvider { id: 1, data: data, title: '', - text: '' + text: '', + channel: 'PushPluginChannel' }, promises = []; From b0c33b1526b91bce03251ff7c12b25387cbd3482 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 16 Apr 2019 17:10:58 +0200 Subject: [PATCH 2/4] MOBILE-2961 push: Use notification icon in foreground --- src/core/pushnotifications/providers/pushnotifications.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index f155eb8be..28bbc77f8 100644 --- a/src/core/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -339,6 +339,13 @@ export class CorePushNotificationsProvider { localNotif.text = notification.message; })); + if (this.utils.isTrueOrOne(data.extrafeatures)) { + // Extra features enabled. + 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); }); From 7723648638581992d42d97378868c5da5d19f88e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 17 Apr 2019 13:17:24 +0200 Subject: [PATCH 3/4] MOBILE-2961 push: Group push notifications in foreground --- .../providers/pushnotifications.ts | 31 +++++++++++++------ src/providers/local-notifications.ts | 13 ++++++-- 2 files changed, 33 insertions(+), 11 deletions(-) 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; From f04c5a4d3cc2a68aa627dac22277db1d78318524 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 25 Apr 2019 17:48:18 +0200 Subject: [PATCH 4/4] MOBILE-2961 config: Use fork of local and push plugins --- config.xml | 4 ++-- package-lock.json | 13 ++++++------- package.json | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/config.xml b/config.xml index 4b3c43d65..ad5096d54 100644 --- a/config.xml +++ b/config.xml @@ -129,7 +129,7 @@ - + @@ -139,7 +139,7 @@ - + diff --git a/package-lock.json b/package-lock.json index efde4ebc4..4e89f7b0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3173,9 +3173,8 @@ "integrity": "sha512-6ucQ6FdlLdBm8kJfFnzozmBTjru/0xekHP/dAhjoCZggkGRlgs8TsUJFkxa/bV+qi7Dlo50JjmpE4UMWAO+aOQ==" }, "cordova-plugin-local-notification": { - "version": "0.9.0-beta.3", - "resolved": "https://registry.npmjs.org/cordova-plugin-local-notification/-/cordova-plugin-local-notification-0.9.0-beta.3.tgz", - "integrity": "sha512-L3Z1velxrkm9nHFcvLnMgBPZjKFt6hwM6hn1lA+JFwIR26Yw6UF72z+/lRMBclAcOxBIDYCqeaLgvezmajjuEg==" + "version": "git+https://github.com/moodlemobile/cordova-plugin-local-notifications.git#5b2f3073a1c1fb39cad3566be792445c343db2c6", + "from": "git+https://github.com/moodlemobile/cordova-plugin-local-notifications.git#moodle" }, "cordova-plugin-media-capture": { "version": "3.0.2", @@ -3600,7 +3599,7 @@ }, "readable-stream": { "version": "1.1.14", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", "dev": true, "requires": { @@ -5972,7 +5971,7 @@ }, "chalk": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { @@ -8575,8 +8574,8 @@ "integrity": "sha512-1wvc3iQOQpEBaQbXgLxA2JUiLSQ2azdF/bF29ghXDiQJWSpQ1BF8gSuqttM8WZoj081Ps8OKL0gYxdDBkFNPqA==" }, "phonegap-plugin-push": { - "version": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#b2fb84bab47d2a86e934893394d8667eec82f0e8", - "from": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle-v2", + "version": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#cf8101e86adb774ae1d7ad6b65fb9d8802673f4b", + "from": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle-v3", "requires": { "babel-plugin-add-header-comment": "^1.0.3", "install": "^0.8.2" diff --git a/package.json b/package.json index ee9784dba..0c5fc0d62 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "cordova-plugin-globalization": "^1.11.0", "cordova-plugin-inappbrowser": "^3.0.0", "cordova-plugin-ionic-keyboard": "^2.1.3", - "cordova-plugin-local-notification": "0.9.0-beta.3", + "cordova-plugin-local-notification": "git+https://github.com/moodlemobile/cordova-plugin-local-notifications.git#moodle", "cordova-plugin-media-capture": "^3.0.2", "cordova-plugin-network-information": "^2.0.1", "cordova-plugin-screen-orientation": "^3.0.1", @@ -111,7 +111,7 @@ "moment": "^2.22.2", "nl.kingsquare.cordova.background-audio": "^1.0.1", "phonegap-plugin-multidex": "^1.0.0", - "phonegap-plugin-push": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle-v2", + "phonegap-plugin-push": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle-v3", "promise.prototype.finally": "^3.1.0", "rxjs": "^5.5.11", "sw-toolbox": "^3.6.0",