From 30f8efd14a8b751a7191e0d66a914dcdcf92b260 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 31 Jan 2019 15:45:45 +0100 Subject: [PATCH 1/8] MOBILE-2831 core: Update push plugin and add new files --- GoogleService-Info.plist | 40 +++++++++++++++++ config.xml | 7 ++- google-services.json | 45 +++++++++++++++++++ package-lock.json | 29 +++++++++++- package.json | 7 ++- .../providers/pushnotifications.ts | 1 - src/config.json | 1 - 7 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 GoogleService-Info.plist create mode 100644 google-services.json diff --git a/GoogleService-Info.plist b/GoogleService-Info.plist new file mode 100644 index 000000000..b80564cf9 --- /dev/null +++ b/GoogleService-Info.plist @@ -0,0 +1,40 @@ + + + + + AD_UNIT_ID_FOR_BANNER_TEST + ca-app-pub-3940256099942544/2934735716 + AD_UNIT_ID_FOR_INTERSTITIAL_TEST + ca-app-pub-3940256099942544/4411468910 + CLIENT_ID + 694767596569-c2cjrca92k99f6nkp3363lsb7ljhdgdr.apps.googleusercontent.com + REVERSED_CLIENT_ID + com.googleusercontent.apps.694767596569-c2cjrca92k99f6nkp3363lsb7ljhdgdr + API_KEY + AIzaSyA-77ZjkxII6GV97CC9rdUl83rzdEXu_rM + GCM_SENDER_ID + 694767596569 + PLIST_VERSION + 1 + BUNDLE_ID + com.moodle.moodlemobile + PROJECT_ID + moodlemobile-push + STORAGE_BUCKET + moodlemobile-push.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:694767596569:ios:a4cdad4d168c9d1a + DATABASE_URL + https://moodlemobile-push.firebaseio.com + + \ No newline at end of file diff --git a/config.xml b/config.xml index cdc0b199d..b39ed9cd6 100644 --- a/config.xml +++ b/config.xml @@ -41,6 +41,7 @@ + @@ -77,6 +78,7 @@ + @@ -137,8 +139,9 @@ - - + + + diff --git a/google-services.json b/google-services.json new file mode 100644 index 000000000..ff50800df --- /dev/null +++ b/google-services.json @@ -0,0 +1,45 @@ +{ + "project_info": { + "project_number": "694767596569", + "firebase_url": "https://moodlemobile-push.firebaseio.com", + "project_id": "moodlemobile-push", + "storage_bucket": "moodlemobile-push.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:694767596569:android:a4cdad4d168c9d1a", + "android_client_info": { + "package_name": "com.moodle.moodlemobile" + } + }, + "oauth_client": [ + { + "client_id": "694767596569-icveqqa2n56oh44l6ev1dr2oh67nh8il.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyCb2zogu0P_aZ2LNgdwzshWExITPKTXJyk" + }, + { + "current_key": "AIzaSyDRT1HwT0gSsTty0whOVtoNKAh8SPrJXLE" + } + ], + "services": { + "analytics_service": { + "status": 1 + }, + "appinvite_service": { + "status": 1, + "other_platform_oauth_client": [] + }, + "ads_service": { + "status": 2 + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a72c22b50..0f114980d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1716,6 +1716,11 @@ } } }, + "babel-plugin-add-header-comment": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/babel-plugin-add-header-comment/-/babel-plugin-add-header-comment-1.0.3.tgz", + "integrity": "sha1-URxJAQYmQNWkgLSsPt1pRBlYUOw=" + }, "bach": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/bach/-/bach-1.2.0.tgz", @@ -3220,6 +3225,11 @@ "resolved": "https://registry.npmjs.org/cordova-sqlite-storage-dependencies/-/cordova-sqlite-storage-dependencies-1.2.1.tgz", "integrity": "sha512-4ihQApBGVKR1QZ4oOSGctKFfthtCfiWMTcIIfxe97vKxlvGr9NyXOvYG9vXU9S7yVR7Ua+Rj47hkE7pQIKvQTg==" }, + "cordova-support-google-services": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/cordova-support-google-services/-/cordova-support-google-services-1.1.0.tgz", + "integrity": "sha1-RjTFIgD4cGDReV6yhw6ZRC12Lm0=" + }, "core-js": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.3.0.tgz", @@ -6314,6 +6324,11 @@ "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "dev": true }, + "install": { + "version": "0.8.9", + "resolved": "https://registry.npmjs.org/install/-/install-0.8.9.tgz", + "integrity": "sha1-n0tcDRhR74cunfheT3Fi1OXc2+0=" + }, "interpret": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.1.0.tgz", @@ -8554,9 +8569,19 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "dev": true }, + "phonegap-plugin-multidex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/phonegap-plugin-multidex/-/phonegap-plugin-multidex-1.0.0.tgz", + "integrity": "sha512-1wvc3iQOQpEBaQbXgLxA2JUiLSQ2azdF/bF29ghXDiQJWSpQ1BF8gSuqttM8WZoj081Ps8OKL0gYxdDBkFNPqA==" + }, "phonegap-plugin-push": { - "version": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#cf2ed2075d9d2d58a4c4f79543f669ed6366c148", - "from": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle" + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/phonegap-plugin-push/-/phonegap-plugin-push-2.2.3.tgz", + "integrity": "sha512-5mjT0G1vfRhXVnZFLwjfzcFwYjVRMibgYDCfYvEujGsP8YwwrIIzcf+xBYAjQV/W2JCjzuNaYd7xJ0yVQaPeig==", + "requires": { + "babel-plugin-add-header-comment": "^1.0.3", + "install": "^0.8.2" + } }, "pify": { "version": "2.3.0", diff --git a/package.json b/package.json index 87f697455..c221f3a8e 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,7 @@ "cordova-plugin-whitelist": "^1.3.3", "cordova-plugin-zip": "^3.1.0", "cordova-sqlite-storage": "^2.6.0", + "cordova-support-google-services": "^1.1.0", "es6-promise-plugin": "^4.2.2", "font-awesome": "^4.7.0", "ionic-angular": "3.9.3", @@ -109,7 +110,8 @@ "jszip": "^3.1.5", "moment": "^2.22.2", "nl.kingsquare.cordova.background-audio": "^1.0.1", - "phonegap-plugin-push": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle", + "phonegap-plugin-multidex": "^1.0.0", + "phonegap-plugin-push": "^2.2.3", "promise.prototype.finally": "^3.1.0", "rxjs": "^5.5.11", "sw-toolbox": "^3.6.0", @@ -169,7 +171,8 @@ "cordova-sqlite-storage": {}, "nl.kingsquare.cordova.background-audio": {}, "phonegap-plugin-push": { - "SENDER_ID": "694767596569" + "ANDROID_SUPPORT_V13_VERSION": "27.+", + "FCM_VERSION": "11.6.2" } } }, diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/addon/pushnotifications/providers/pushnotifications.ts index fce797a79..6cd40d65b 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/addon/pushnotifications/providers/pushnotifications.ts @@ -94,7 +94,6 @@ export class AddonPushNotificationsProvider { return this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((soundEnabled) => { return { android: { - senderID: CoreConfigConstants.gcmpn, sound: !!soundEnabled, icon: 'smallicon' }, diff --git a/src/config.json b/src/config.json index 56244a5a5..331a72b6d 100644 --- a/src/config.json +++ b/src/config.json @@ -64,7 +64,6 @@ "password": "moodle" } }, - "gcmpn": "694767596569", "customurlscheme": "moodlemobile", "siteurl": "", "multisitesdisplay": "", From cca7dee8eb76d3bca31831fe8f72836bafc1b943 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 1 Feb 2019 15:35:13 +0100 Subject: [PATCH 2/8] MOBILE-2831 push: Handle notification channels --- scripts/langindex.json | 2 + src/addon/calendar/lang/en.json | 1 + .../providers/pushnotifications.ts | 45 ++++++++++++++----- src/assets/lang/en.json | 2 + src/lang/en.json | 1 + src/providers/local-notifications.ts | 26 ++++++++++- 6 files changed, 65 insertions(+), 12 deletions(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index 92ad0f979..15958c458 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -68,6 +68,7 @@ "addon.blog.siteblogheading": "blog", "addon.calendar.calendar": "calendar", "addon.calendar.calendarevents": "local_moodlemobileapp", + "addon.calendar.calendarreminders": "local_moodlemobileapp", "addon.calendar.defaultnotificationtime": "local_moodlemobileapp", "addon.calendar.errorloadevent": "local_moodlemobileapp", "addon.calendar.errorloadevents": "local_moodlemobileapp", @@ -1506,6 +1507,7 @@ "core.maxsizeandattachments": "moodle", "core.min": "moodle", "core.mins": "moodle", + "core.misc": "admin", "core.mod_assign": "assign/pluginname", "core.mod_assignment": "assignment/pluginname", "core.mod_book": "book/pluginname", diff --git a/src/addon/calendar/lang/en.json b/src/addon/calendar/lang/en.json index 1fc6d2e34..6ccb04caa 100644 --- a/src/addon/calendar/lang/en.json +++ b/src/addon/calendar/lang/en.json @@ -1,6 +1,7 @@ { "calendar": "Calendar", "calendarevents": "Calendar events", + "calendarreminders": "Calendar reminders", "defaultnotificationtime": "Default notification time", "errorloadevent": "Error loading event.", "errorloadevents": "Error loading events.", diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/addon/pushnotifications/providers/pushnotifications.ts index 6cd40d65b..63944830c 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/addon/pushnotifications/providers/pushnotifications.ts @@ -13,9 +13,11 @@ // limitations under the License. import { Injectable, NgZone } from '@angular/core'; +import { Platform } from 'ionic-angular'; import { Badge } from '@ionic-native/badge'; import { Push, PushObject, PushOptions } from '@ionic-native/push'; import { Device } from '@ionic-native/device'; +import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from '@providers/app'; import { CoreInitDelegate } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; @@ -67,10 +69,21 @@ export class AddonPushNotificationsProvider { protected pushNotificationsDelegate: AddonPushNotificationsDelegate, protected sitesProvider: CoreSitesProvider, private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider, private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push, - private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone) { + private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone, + private translate: TranslateService, private platform: Platform) { this.logger = logger.getInstance('AddonPushNotificationsProvider'); this.appDB = appProvider.getDB(); this.appDB.createTablesFromSchema(this.tablesSchema); + + platform.ready().then(() => { + // Create the default channel. + this.createDefaultChannel(); + + translate.onLangChange.subscribe((event: any) => { + // Update the channel name. + this.createDefaultChannel(); + }); + }); } /** @@ -85,6 +98,25 @@ export class AddonPushNotificationsProvider { }); } + /** + * Create the default push channel. It is used to change the name. + * + * @return {Promise} Promise resolved when done. + */ + protected createDefaultChannel(): Promise { + if (!this.platform.is('android')) { + return Promise.resolve(); + } + + return this.push.createChannel({ + id: 'PushPluginChannel', + description: this.translate.instant('core.misc'), + importance: 4 + }).catch((error) => { + this.logger.error('Error changing push channel name', error); + }); + } + /** * Returns options for push notifications based on device. * @@ -155,13 +187,7 @@ export class AddonPushNotificationsProvider { if (this.localNotificationsProvider.isAvailable()) { const localNotif: ILocalNotification = { id: 1, - trigger: { - at: new Date() - }, - data: { - notif: data.notif, - site: data.site - }, + data: data, title: '', text: '' }, @@ -193,9 +219,6 @@ export class AddonPushNotificationsProvider { }); } else { // The notification was clicked. - // For compatibility with old push plugin implementation we'll merge all the notification data in a single object. - data.title = notification.title; - data.message = notification.message; this.notificationClicked(data); } }); diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 0731749b0..1ce4bc648 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -68,6 +68,7 @@ "addon.blog.siteblogheading": "Site blog", "addon.calendar.calendar": "Calendar", "addon.calendar.calendarevents": "Calendar events", + "addon.calendar.calendarreminders": "Calendar reminders", "addon.calendar.defaultnotificationtime": "Default notification time", "addon.calendar.errorloadevent": "Error loading event.", "addon.calendar.errorloadevents": "Error loading events.", @@ -1506,6 +1507,7 @@ "core.maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}", "core.min": "min", "core.mins": "mins", + "core.misc": "Miscellaneous", "core.mod_assign": "Assignment", "core.mod_assignment": "Assignment 2.2 (Disabled)", "core.mod_book": "Book", diff --git a/src/lang/en.json b/src/lang/en.json index 65c423bd1..7b7086f67 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -126,6 +126,7 @@ "maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}", "min": "min", "mins": "mins", + "misc": "Miscellaneous", "mod_assign": "Assignment", "mod_assignment": "Assignment 2.2 (Disabled)", "mod_book": "Book", diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts index 40cfc3926..03b2995b7 100644 --- a/src/providers/local-notifications.ts +++ b/src/providers/local-notifications.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { Platform, Alert, AlertController } from 'ionic-angular'; import { LocalNotifications, ILocalNotification } from '@ionic-native/local-notifications'; +import { Push } from '@ionic-native/push'; import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from './app'; import { CoreConfigProvider } from './config'; @@ -104,7 +105,7 @@ export class CoreLocalNotificationsProvider { constructor(logger: CoreLoggerProvider, private localNotifications: LocalNotifications, private platform: Platform, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private configProvider: CoreConfigProvider, private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController, - eventsProvider: CoreEventsProvider) { + eventsProvider: CoreEventsProvider, private push: Push) { this.logger = logger.getInstance('CoreLocalNotificationsProvider'); this.appDB = appProvider.getDB(); @@ -122,6 +123,14 @@ export class CoreLocalNotificationsProvider { this.notifyClick(notification.data); } }); + + // Create the default channel for local notifications. + this.createDefaultChannel(); + + translate.onLangChange.subscribe((event: any) => { + // Update the channel name. + this.createDefaultChannel(); + }); }); eventsProvider.on(CoreEventsProvider.SITE_DELETED, (site) => { @@ -176,6 +185,21 @@ export class CoreLocalNotificationsProvider { }); } + /** + * Create the default channel. It is used to change the name. + * + * @return {Promise} Promise resolved when done. + */ + protected createDefaultChannel(): Promise { + return this.push.createChannel({ + id: 'default-channel-id', + description: this.translate.instant('addon.calendar.calendarreminders'), + importance: 4 + }).catch((error) => { + this.logger.error('Error changing channel name', error); + }); + } + /** * Get a code to create unique notifications. If there's no code assigned, create a new one. * From f3e72d283aa23f69309a4e7c48c0b155675b8807 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 14 Feb 2019 10:37:23 +0100 Subject: [PATCH 3/8] MOBILE-2831 core: Use beta 3 of local-notifications plugin --- config.xml | 2 +- package-lock.json | 12 ++++++------ package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config.xml b/config.xml index b39ed9cd6..265b5a0a5 100644 --- a/config.xml +++ b/config.xml @@ -129,7 +129,7 @@ - + diff --git a/package-lock.json b/package-lock.json index 0f114980d..8b112c0e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -161,9 +161,9 @@ "integrity": "sha512-2BHO1bV4mehWZNfdsWQ/uojxYFNvk4I6u0KYnNb61RiJRY83joCEw3oFkOMRGLZthPf6TN1cueZUIAGMHXA3nA==" }, "@ionic-native/local-notifications": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/@ionic-native/local-notifications/-/local-notifications-4.17.0.tgz", - "integrity": "sha512-NGLGtGRduRU3f/4N2nv4hF550+NkJ9CP7mOS9vlZcZJBzlIup9X67u1M2j/+KFOpWqzS2avZ1gvZbxOmCjPNPw==" + "version": "4.20.0", + "resolved": "https://registry.npmjs.org/@ionic-native/local-notifications/-/local-notifications-4.20.0.tgz", + "integrity": "sha512-Ht/0zau8/2+G/bH/okXXhhWB6YrkCNL2QxVJHQ2dophXFGxQPOZAN3CKWhuQSjfbr76fa2nvQXF6jsXLpIR/ng==" }, "@ionic-native/media-capture": { "version": "4.17.0", @@ -3173,9 +3173,9 @@ "integrity": "sha512-6ucQ6FdlLdBm8kJfFnzozmBTjru/0xekHP/dAhjoCZggkGRlgs8TsUJFkxa/bV+qi7Dlo50JjmpE4UMWAO+aOQ==" }, "cordova-plugin-local-notification": { - "version": "0.9.0-beta.2", - "resolved": "https://registry.npmjs.org/cordova-plugin-local-notification/-/cordova-plugin-local-notification-0.9.0-beta.2.tgz", - "integrity": "sha512-63n77K1pt8dnbWnNR8QWETi9Glezi1bvNHvHWmGNIOv0xCb0phZnm+Ku49BQ+omwe8Z5voMvrA4I03SYPpv38w==" + "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==" }, "cordova-plugin-media-capture": { "version": "3.0.2", diff --git a/package.json b/package.json index c221f3a8e..4ffaa3c37 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.2", + "cordova-plugin-local-notification": "^0.9.0-beta.3", "cordova-plugin-media-capture": "^3.0.2", "cordova-plugin-network-information": "^2.0.1", "cordova-plugin-screen-orientation": "^3.0.1", From 10f54e714938ba841221e802cf4417201f2ef07a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 14 Feb 2019 10:34:44 +0100 Subject: [PATCH 4/8] MOBILE-2831 core: Fix local notifications in iOS --- src/core/emulator/providers/local-notifications.ts | 11 ++--------- src/providers/local-notifications.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/emulator/providers/local-notifications.ts b/src/core/emulator/providers/local-notifications.ts index f8e4f0f65..bcf07ca6b 100644 --- a/src/core/emulator/providers/local-notifications.ts +++ b/src/core/emulator/providers/local-notifications.ts @@ -939,6 +939,8 @@ export class LocalNotificationsMock extends LocalNotifications { /** * Schedules or updates a single or multiple notifications. + * We only support using the "at" property to trigger the notification. Other properties like "in" or "every" + * aren't supported yet. * * @param {ILocalNotification | Array} [options] Notification or notifications. * @param {string} [eventName] Name of the event: schedule or update. @@ -978,15 +980,6 @@ export class LocalNotificationsMock extends LocalNotifications { // Launch the trigger event. this.fireEvent('trigger', notification); - - if (notification.trigger.every && this.scheduled[notification.id] && - !this.scheduled[notification.id].interval) { - - const interval = this.parseInterval(notification.trigger.every); - if (interval > 0) { - this.scheduled[notification.id].interval = setInterval(trigger, interval); - } - } }; this.scheduled[notification.id].timeout = setTimeout(trigger, toTriggerTime); diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts index 03b2995b7..6c6b7df7c 100644 --- a/src/providers/local-notifications.ts +++ b/src/providers/local-notifications.ts @@ -191,6 +191,10 @@ export class CoreLocalNotificationsProvider { * @return {Promise} Promise resolved when done. */ protected createDefaultChannel(): Promise { + if (!this.platform.is('android')) { + return Promise.resolve(); + } + return this.push.createChannel({ id: 'default-channel-id', description: this.translate.instant('addon.calendar.calendarreminders'), @@ -293,7 +297,8 @@ export class CoreLocalNotificationsProvider { isAvailable(): boolean { const win = window; - return this.appProvider.isDesktop() || !!(win.plugin && win.plugin.notification && win.plugin.notification.local); + return this.appProvider.isDesktop() || !!(win.cordova && win.cordova.plugins && win.cordova.plugins.notification && + win.cordova.plugins.notification.local); } /** @@ -506,6 +511,8 @@ export class CoreLocalNotificationsProvider { delete notification.sound; // Use default value. } + notification.foreground = true; + // Remove from triggered, since the notification could be in there with a different time. this.removeTriggered(notification.id); this.localNotifications.schedule(notification); From 75a273214175209f495fc20517d0f8bd4a8c3ec1 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 15 Feb 2019 13:54:29 +0100 Subject: [PATCH 5/8] MOBILE-2831 push: Add fcm suffix to platform --- src/addon/pushnotifications/providers/pushnotifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/addon/pushnotifications/providers/pushnotifications.ts index 63944830c..46be2c89e 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/addon/pushnotifications/providers/pushnotifications.ts @@ -403,7 +403,7 @@ export class AddonPushNotificationsProvider { appid: CoreConfigConstants.app_id, name: this.device.manufacturer || '', model: this.device.model, - platform: this.device.platform, + platform: this.device.platform + '-fcm', version: this.device.version, pushid: this.pushID, uuid: this.device.uuid From a9e4e0c5288bec74ab6e28270805884cfbb219ae Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 5 Mar 2019 09:18:07 +0100 Subject: [PATCH 6/8] MOBILE-2831 push: Unregister before register if needed --- .../providers/pushnotifications.ts | 233 ++++++++++++++++-- .../providers/register-cron-handler.ts | 71 ++++++ .../pushnotifications.module.ts | 11 +- 3 files changed, 293 insertions(+), 22 deletions(-) create mode 100644 src/addon/pushnotifications/providers/register-cron-handler.ts diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/addon/pushnotifications/providers/pushnotifications.ts index 46be2c89e..adb48e419 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/addon/pushnotifications/providers/pushnotifications.ts @@ -21,7 +21,7 @@ import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from '@providers/app'; import { CoreInitDelegate } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { AddonPushNotificationsDelegate } from './delegate'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreUtilsProvider } from '@providers/utils/utils'; @@ -31,6 +31,54 @@ import { CoreConstants } from '@core/constants'; import { CoreConfigConstants } from '../../../configconstants'; import { ILocalNotification } from '@ionic-native/local-notifications'; import { SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { CoreSite } from '@classes/site'; + +/** + * Data needed to register a device in a Moodle site. + */ +export interface AddonPushNotificationsRegisterData { + /** + * App ID. + * @type {string} + */ + appid: string; + + /** + * Device UUID. + * @type {string} + */ + uuid: string; + + /** + * Device name. + * @type {string} + */ + name: string; + + /** + * Device model. + * @type {string} + */ + model: string; + + /** + * Device platform. + * @type {string} + */ + platform: string; + + /** + * Device version. + * @type {string} + */ + version: string; + + /** + * Push ID. + * @type {string} + */ + pushid: string; +} /** * Service to handle push notifications. @@ -44,7 +92,8 @@ export class AddonPushNotificationsProvider { // Variables for database. static BADGE_TABLE = 'addon_pushnotifications_badge'; - protected tablesSchema: SQLiteDBTableSchema[] = [ + static REGISTERED_DEVICES_TABLE = 'addon_pushnotifications_registered_devices'; + protected appTablesSchema: SQLiteDBTableSchema[] = [ { name: AddonPushNotificationsProvider.BADGE_TABLE, columns: [ @@ -64,6 +113,46 @@ export class AddonPushNotificationsProvider { primaryKeys: ['siteid', 'addon'] } ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonPushNotificationsProvider', + version: 1, + tables: [ + { + name: AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, + columns: [ + { + name: 'appid', + type: 'TEXT', + }, + { + name: 'uuid', + type: 'TEXT' + }, + { + name: 'name', + type: 'TEXT' + }, + { + name: 'model', + type: 'TEXT' + }, + { + name: 'platform', + type: 'TEXT' + }, + { + name: 'version', + type: 'TEXT' + }, + { + name: 'pushid', + type: 'TEXT' + }, + ], + primaryKeys: ['appid', 'uuid'] + } + ], + }; constructor(logger: CoreLoggerProvider, protected appProvider: CoreAppProvider, private initDelegate: CoreInitDelegate, protected pushNotificationsDelegate: AddonPushNotificationsDelegate, protected sitesProvider: CoreSitesProvider, @@ -73,7 +162,8 @@ export class AddonPushNotificationsProvider { private translate: TranslateService, private platform: Platform) { this.logger = logger.getInstance('AddonPushNotificationsProvider'); this.appDB = appProvider.getDB(); - this.appDB.createTablesFromSchema(this.tablesSchema); + this.appDB.createTablesFromSchema(this.appTablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); platform.ready().then(() => { // Create the default channel. @@ -150,6 +240,23 @@ export class AddonPushNotificationsProvider { return this.pushID; } + /** + * Get data to register the device in Moodle. + * + * @return {AddonPushNotificationsRegisterData} Data. + */ + protected getRegisterData(): AddonPushNotificationsRegisterData { + return { + appid: CoreConfigConstants.app_id, + name: this.device.manufacturer || '', + model: this.device.model, + platform: this.device.platform + '-fcm', + version: this.device.version, + pushid: this.pushID, + uuid: this.device.uuid + }; + } + /** * Get Sitebadge counter from the database. * @@ -227,10 +334,10 @@ export class AddonPushNotificationsProvider { /** * Unregisters a device from a certain Moodle site. * - * @param {any} site Site to unregister from. - * @return {Promise} Promise resolved when device is unregistered. + * @param {CoreSite} site Site to unregister from. + * @return {Promise} Promise resolved when device is unregistered. */ - unregisterDeviceOnMoodle(site: any): Promise { + unregisterDeviceOnMoodle(site: CoreSite): Promise { if (!site || !this.appProvider.isMobile()) { return Promise.reject(null); } @@ -246,6 +353,12 @@ export class AddonPushNotificationsProvider { if (!response || !response.removed) { return Promise.reject(null); } + + // Remove the device from the local DB. + return site.getDb().deleteRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, this.getRegisterData()) + .catch(() => { + // Ignore errors. + }); }); } @@ -388,28 +501,54 @@ export class AddonPushNotificationsProvider { } /** - * Registers a device on current Moodle site. + * Registers a device on a Moodle site if needed. * - * @return {Promise} Promise resolved when device is registered. + * @param {string} [siteId] Site ID. If not defined, current site. + * @param {boolean} [forceUnregister] Whether to force unregister and register. + * @return {Promise} Promise resolved when device is registered. */ - registerDeviceOnMoodle(): Promise { + registerDeviceOnMoodle(siteId?: string, forceUnregister?: boolean): Promise { this.logger.debug('Register device on Moodle.'); - if (!this.sitesProvider.isLoggedIn() || !this.pushID || !this.appProvider.isMobile()) { + if (!this.pushID || !this.appProvider.isMobile()) { return Promise.reject(null); } - const data = { - appid: CoreConfigConstants.app_id, - name: this.device.manufacturer || '', - model: this.device.model, - platform: this.device.platform + '-fcm', - version: this.device.version, - pushid: this.pushID, - uuid: this.device.uuid - }; + const data = this.getRegisterData(); + let result, + site: CoreSite; + + return this.sitesProvider.getSite(siteId).then((s) => { + site = s; + + if (forceUnregister) { + return {unregister: true, register: true}; + } else { + // Check if the device is already registered. + return this.shouldRegister(data, site); + } + }).then((res) => { + result = res; + + if (result.unregister) { + // Unregister the device first. + return this.unregisterDeviceOnMoodle(site).catch(() => { + // Ignore errors. + }); + } + }).then(() => { + if (result.register) { + // Now register the device. + return site.write('core_user_add_user_device', this.utils.clone(data)).then((response) => { + // Insert the device in the local DB. + return site.getDb().insertRecord(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, data) + .catch((error) => { + // Ignore errors. + }); + }); + } + }); - return this.sitesProvider.getCurrentSite().write('core_user_add_user_device', data); } /** @@ -448,4 +587,58 @@ export class AddonPushNotificationsProvider { return value; }); } + + /** + * Check if device should be registered (and unregistered first). + * + * @param {AddonPushNotificationsRegisterData} data Data of the device. + * @param {CoreSite} site Site to use. + * @return {Promise<{register: boolean, unregister: boolean}>} Promise resolved with booleans: whether to register/unregister. + */ + protected shouldRegister(data: AddonPushNotificationsRegisterData, site: CoreSite) + : Promise<{register: boolean, unregister: boolean}> { + + // Check if the device is already registered. + return site.getDb().getRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, { + appid: data.appid, + uuid: data.uuid + }).catch(() => { + // Ignore errors. + return []; + }).then((records: AddonPushNotificationsRegisterData[]) => { + let isStored = false, + versionOrPushChanged = false; + + records.forEach((record) => { + if (record.name == data.name && record.model == data.model && record.platform == data.platform) { + if (record.version == data.version && record.pushid == data.pushid) { + // The device is already stored. + isStored = true; + } else { + // The version or pushid has changed. + versionOrPushChanged = true; + } + } + }); + + if (isStored) { + // The device has already been registered, no need to register it again. + return { + register: false, + unregister: false + }; + } else if (versionOrPushChanged) { + // This data can be updated by calling register WS, no need to call unregister. + return { + register: true, + unregister: false + }; + } else { + return { + register: true, + unregister: true + }; + } + }); + } } diff --git a/src/addon/pushnotifications/providers/register-cron-handler.ts b/src/addon/pushnotifications/providers/register-cron-handler.ts new file mode 100644 index 000000000..fd3ea87ff --- /dev/null +++ b/src/addon/pushnotifications/providers/register-cron-handler.ts @@ -0,0 +1,71 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { CoreCronHandler } from '@providers/cron'; +import { AddonPushNotificationsProvider } from './pushnotifications'; + +/** + * Cron handler to force a register on a Moodle site when a site is manually synchronized. + */ +@Injectable() +export class AddonPushNotificationsRegisterCronHandler implements CoreCronHandler { + name = 'AddonPushNotificationsRegisterCronHandler'; + + constructor(private pushNotificationsProvider: AddonPushNotificationsProvider) {} + + /** + * Check whether the sync can be executed manually. Call isSync if not defined. + * + * @return {boolean} Whether the sync can be executed manually. + */ + canManualSync(): boolean { + return true; // Execute the handler when the site is manually synchronized. + } + + /** + * Execute the process. + * Receives the ID of the site affected, undefined for all sites. + * + * @param {string} [siteId] ID of the site affected, undefined for all sites. + * @return {Promise} Promise resolved when done, rejected if failure. + */ + execute(siteId?: string): Promise { + if (!siteId) { + // It's not a specific site, don't do anything. + return Promise.resolve(); + } + + // Register the device again. + return this.pushNotificationsProvider.registerDeviceOnMoodle(siteId, true); + } + + /** + * Get the time between consecutive executions. + * + * @return {number} Time between consecutive executions (in ms). + */ + getInterval(): number { + return 86400000; // 1 day. We won't do anything with automatic execution, so use a big number. + } + + /** + * Check whether it's a synchronization process or not. True if not defined. + * + * @return {boolean} Whether it's a synchronization process or not. + */ + isSync(): boolean { + return false; + } +} diff --git a/src/addon/pushnotifications/pushnotifications.module.ts b/src/addon/pushnotifications/pushnotifications.module.ts index 6de574ecc..9ae4bde6a 100644 --- a/src/addon/pushnotifications/pushnotifications.module.ts +++ b/src/addon/pushnotifications/pushnotifications.module.ts @@ -16,6 +16,8 @@ import { NgModule } from '@angular/core'; import { Platform } from 'ionic-angular'; import { AddonPushNotificationsProvider } from './providers/pushnotifications'; import { AddonPushNotificationsDelegate } from './providers/delegate'; +import { AddonPushNotificationsRegisterCronHandler } from './providers/register-cron-handler'; +import { CoreCronDelegate } from '@providers/cron'; import { CoreEventsProvider } from '@providers/events'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; @@ -34,16 +36,21 @@ export const ADDON_PUSHNOTIFICATIONS_PROVIDERS: any[] = [ ], providers: [ AddonPushNotificationsProvider, - AddonPushNotificationsDelegate + AddonPushNotificationsDelegate, + AddonPushNotificationsRegisterCronHandler ] }) export class AddonPushNotificationsModule { constructor(platform: Platform, pushNotificationsProvider: AddonPushNotificationsProvider, eventsProvider: CoreEventsProvider, localNotificationsProvider: CoreLocalNotificationsProvider, loggerProvider: CoreLoggerProvider, - updateManager: CoreUpdateManagerProvider) { + updateManager: CoreUpdateManagerProvider, cronDelegate: CoreCronDelegate, + registerCronHandler: AddonPushNotificationsRegisterCronHandler) { const logger = loggerProvider.getInstance('AddonPushNotificationsModule'); + // Register the handlers. + cronDelegate.register(registerCronHandler); + // Register device on GCM or APNS server. platform.ready().then(() => { pushNotificationsProvider.registerDevice(); From a8b258ac37d8343a3dd8dcb72812c121b0d06ccf Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 5 Mar 2019 11:30:46 +0100 Subject: [PATCH 7/8] MOBILE-2831 push: Allow unregister from Moodle in offline --- .../providers/pushnotifications.ts | 94 +++++++++++++++++-- .../providers/unregister-cron-handler.ts | 47 ++++++++++ .../pushnotifications.module.ts | 8 +- 3 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 src/addon/pushnotifications/providers/unregister-cron-handler.ts diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/addon/pushnotifications/providers/pushnotifications.ts index adb48e419..df36c3bed 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/addon/pushnotifications/providers/pushnotifications.ts @@ -22,6 +22,7 @@ import { CoreAppProvider } from '@providers/app'; import { CoreInitDelegate } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; +import { CoreSitesFactoryProvider } from '@providers/sites-factory'; import { AddonPushNotificationsDelegate } from './delegate'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreUtilsProvider } from '@providers/utils/utils'; @@ -30,7 +31,7 @@ import { CoreConfigProvider } from '@providers/config'; import { CoreConstants } from '@core/constants'; import { CoreConfigConstants } from '../../../configconstants'; import { ILocalNotification } from '@ionic-native/local-notifications'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; import { CoreSite } from '@classes/site'; /** @@ -87,11 +88,12 @@ export interface AddonPushNotificationsRegisterData { export class AddonPushNotificationsProvider { protected logger; protected pushID: string; - protected appDB: any; + protected appDB: SQLiteDB; static COMPONENT = 'AddonPushNotificationsProvider'; // Variables for database. static BADGE_TABLE = 'addon_pushnotifications_badge'; + static PENDING_UNREGISTER_TABLE = 'addon_pushnotifications_pending_unregister'; static REGISTERED_DEVICES_TABLE = 'addon_pushnotifications_registered_devices'; protected appTablesSchema: SQLiteDBTableSchema[] = [ { @@ -111,6 +113,28 @@ export class AddonPushNotificationsProvider { } ], primaryKeys: ['siteid', 'addon'] + }, + { + name: AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, + columns: [ + { + name: 'siteid', + type: 'TEXT', + primaryKey: true + }, + { + name: 'siteurl', + type: 'TEXT' + }, + { + name: 'token', + type: 'TEXT' + }, + { + name: 'info', + type: 'TEXT' + } + ] } ]; protected siteSchema: CoreSiteSchema = { @@ -159,7 +183,7 @@ export class AddonPushNotificationsProvider { private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider, private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push, private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone, - private translate: TranslateService, private platform: Platform) { + private translate: TranslateService, private platform: Platform, private sitesFactory: CoreSitesFactoryProvider) { this.logger = logger.getInstance('AddonPushNotificationsProvider'); this.appDB = appProvider.getDB(); this.appDB.createTablesFromSchema(this.appTablesSchema); @@ -354,11 +378,33 @@ export class AddonPushNotificationsProvider { return Promise.reject(null); } + const promises = []; + // Remove the device from the local DB. - return site.getDb().deleteRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, this.getRegisterData()) - .catch(() => { + promises.push(site.getDb().deleteRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, + this.getRegisterData())); + + // Remove pending unregisters for this site. + promises.push(this.appDB.deleteRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id})); + + return Promise.all(promises).catch(() => { // Ignore errors. }); + }).catch((error) => { + if (this.utils.isWebServiceError(error)) { + // It's a WebService error, can't unregister. + return Promise.reject(error); + } + + // Store the pending unregister so it's retried again later. + return this.appDB.insertRecord(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, { + siteid: site.id, + siteurl: site.getURL(), + token: site.getToken(), + info: JSON.stringify(site.getInfo()) + }).then(() => { + return Promise.reject(error); + }); }); } @@ -547,8 +593,12 @@ export class AddonPushNotificationsProvider { }); }); } + }).finally(() => { + // Remove pending unregisters for this site. + this.appDB.deleteRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id}).catch(() => { + // Ignore errors. + }); }); - } /** @@ -566,6 +616,38 @@ export class AddonPushNotificationsProvider { }); } + /** + * Retry pending unregisters. + * + * @param {string} [siteId] If defined, retry only for that site if needed. Otherwise, retry all pending unregisters. + * @return {Promise} Promise resolved when done. + */ + retryUnregisters(siteId?: string): Promise { + let promise; + + if (siteId) { + // Check if the site has a pending unregister. + promise = this.appDB.getRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, {siteid: siteId}); + } else { + // Get all pending unregisters. + promise = this.appDB.getAllRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE); + } + + return promise.then((results) => { + const promises = []; + + results.forEach((result) => { + // Create a temporary site to unregister. + const tmpSite = this.sitesFactory.makeSite(result.siteid, result.siteurl, result.token, + this.textUtils.parseJSON(result.info, {})); + + promises.push(this.unregisterDeviceOnMoodle(tmpSite)); + }); + + return Promise.all(promises); + }); + } + /** * Save the addon/site badgecounter on the database. * diff --git a/src/addon/pushnotifications/providers/unregister-cron-handler.ts b/src/addon/pushnotifications/providers/unregister-cron-handler.ts new file mode 100644 index 000000000..548d44bd0 --- /dev/null +++ b/src/addon/pushnotifications/providers/unregister-cron-handler.ts @@ -0,0 +1,47 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { CoreCronHandler } from '@providers/cron'; +import { AddonPushNotificationsProvider } from './pushnotifications'; + +/** + * Cron handler to retry pending unregisters. + */ +@Injectable() +export class AddonPushNotificationsUnregisterCronHandler implements CoreCronHandler { + name = 'AddonPushNotificationsUnregisterCronHandler'; + + constructor(private pushNotificationsProvider: AddonPushNotificationsProvider) {} + + /** + * Execute the process. + * Receives the ID of the site affected, undefined for all sites. + * + * @param {string} [siteId] ID of the site affected, undefined for all sites. + * @return {Promise} Promise resolved when done, rejected if failure. + */ + execute(siteId?: string): Promise { + return this.pushNotificationsProvider.retryUnregisters(siteId); + } + + /** + * Get the time between consecutive executions. + * + * @return {number} Time between consecutive executions (in ms). + */ + getInterval(): number { + return 300000; + } +} diff --git a/src/addon/pushnotifications/pushnotifications.module.ts b/src/addon/pushnotifications/pushnotifications.module.ts index 9ae4bde6a..d36a0ce43 100644 --- a/src/addon/pushnotifications/pushnotifications.module.ts +++ b/src/addon/pushnotifications/pushnotifications.module.ts @@ -17,6 +17,7 @@ import { Platform } from 'ionic-angular'; import { AddonPushNotificationsProvider } from './providers/pushnotifications'; import { AddonPushNotificationsDelegate } from './providers/delegate'; import { AddonPushNotificationsRegisterCronHandler } from './providers/register-cron-handler'; +import { AddonPushNotificationsUnregisterCronHandler } from './providers/unregister-cron-handler'; import { CoreCronDelegate } from '@providers/cron'; import { CoreEventsProvider } from '@providers/events'; import { CoreLoggerProvider } from '@providers/logger'; @@ -37,19 +38,22 @@ export const ADDON_PUSHNOTIFICATIONS_PROVIDERS: any[] = [ providers: [ AddonPushNotificationsProvider, AddonPushNotificationsDelegate, - AddonPushNotificationsRegisterCronHandler + AddonPushNotificationsRegisterCronHandler, + AddonPushNotificationsUnregisterCronHandler ] }) export class AddonPushNotificationsModule { constructor(platform: Platform, pushNotificationsProvider: AddonPushNotificationsProvider, eventsProvider: CoreEventsProvider, localNotificationsProvider: CoreLocalNotificationsProvider, loggerProvider: CoreLoggerProvider, updateManager: CoreUpdateManagerProvider, cronDelegate: CoreCronDelegate, - registerCronHandler: AddonPushNotificationsRegisterCronHandler) { + registerCronHandler: AddonPushNotificationsRegisterCronHandler, + unregisterCronHandler: AddonPushNotificationsUnregisterCronHandler) { const logger = loggerProvider.getInstance('AddonPushNotificationsModule'); // Register the handlers. cronDelegate.register(registerCronHandler); + cronDelegate.register(unregisterCronHandler); // Register device on GCM or APNS server. platform.ready().then(() => { From 2ec4b536a59b61d62863542d79500f463e00f4f7 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 6 Mar 2019 12:47:20 +0100 Subject: [PATCH 8/8] MOBILE-2831 settings: Display push ID in about page --- scripts/langindex.json | 1 + src/assets/lang/en.json | 1 + src/core/settings/lang/en.json | 1 + src/core/settings/pages/about/about.html | 4 ++++ src/core/settings/pages/about/about.ts | 5 ++++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index 15958c458..96590e260 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1651,6 +1651,7 @@ "core.settings.navigatoruseragent": "local_moodlemobileapp", "core.settings.networkstatus": "local_moodlemobileapp", "core.settings.privacypolicy": "local_moodlemobileapp", + "core.settings.pushid": "local_moodlemobileapp", "core.settings.reportinbackground": "local_moodlemobileapp", "core.settings.settings": "moodle", "core.settings.showdownloadoptions": "local_moodlemobileapp", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 1ce4bc648..c6751cfb1 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1651,6 +1651,7 @@ "core.settings.navigatoruseragent": "Navigator userAgent", "core.settings.networkstatus": "Internet connection status", "core.settings.privacypolicy": "Privacy policy", + "core.settings.pushid": "Push notifications ID", "core.settings.reportinbackground": "Report errors automatically", "core.settings.settings": "Settings", "core.settings.showdownloadoptions": "Show download options", diff --git a/src/core/settings/lang/en.json b/src/core/settings/lang/en.json index 2b95b657e..a960ccf02 100644 --- a/src/core/settings/lang/en.json +++ b/src/core/settings/lang/en.json @@ -40,6 +40,7 @@ "navigatoruseragent": "Navigator userAgent", "networkstatus": "Internet connection status", "privacypolicy": "Privacy policy", + "pushid": "Push notifications ID", "reportinbackground": "Report errors automatically", "settings": "Settings", "showdownloadoptions": "Show download options", diff --git a/src/core/settings/pages/about/about.html b/src/core/settings/pages/about/about.html index 8efcfaa14..65dd36145 100644 --- a/src/core/settings/pages/about/about.html +++ b/src/core/settings/pages/about/about.html @@ -106,6 +106,10 @@

{{ 'core.settings.cordovadeviceuuid' | translate}}

{{ device.uuid }}

+ +

{{ 'core.settings.pushid' | translate}}

+

{{ pushId }}

+

{{ 'core.settings.localnotifavailable' | translate}}

{{ localNotifAvailable | translate }}

diff --git a/src/core/settings/pages/about/about.ts b/src/core/settings/pages/about/about.ts index 3bdebc52b..3c6497f49 100644 --- a/src/core/settings/pages/about/about.ts +++ b/src/core/settings/pages/about/about.ts @@ -22,6 +22,7 @@ import { CoreLangProvider } from '@providers/lang'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreSitesProvider } from '@providers/sites'; import { CoreConfigConstants } from '../../../../configconstants'; +import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications'; /** * Page that displays the about settings. @@ -53,10 +54,11 @@ export class CoreSettingsAboutPage { fsClickable: boolean; storageType: string; localNotifAvailable: string; + pushId: string; constructor(platform: Platform, device: Device, appProvider: CoreAppProvider, fileProvider: CoreFileProvider, initDelegate: CoreInitDelegate, langProvider: CoreLangProvider, sitesProvider: CoreSitesProvider, - localNotificationsProvider: CoreLocalNotificationsProvider) { + localNotificationsProvider: CoreLocalNotificationsProvider, pushNotificationsProvider: AddonPushNotificationsProvider) { const currentSite = sitesProvider.getCurrentSite(); @@ -111,5 +113,6 @@ export class CoreSettingsAboutPage { } this.localNotifAvailable = localNotificationsProvider.isAvailable() ? 'core.yes' : 'core.no'; + this.pushId = pushNotificationsProvider.getPushId(); } }