diff --git a/package-lock.json b/package-lock.json index bd19b7d92..cb2ada6bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4197,21 +4197,6 @@ } } }, - "@ionic-native/push": { - "version": "5.36.0", - "resolved": "https://registry.npmjs.org/@ionic-native/push/-/push-5.36.0.tgz", - "integrity": "sha512-N2Ei6qsIYOmqfz/kH9XpKeIp3C5Qe9NXebzH2ytkpwBApPiCc6h+9LOxgMB/rls9VfT0V0ZoxvJbac9UZ6SJmA==", - "requires": { - "@types/cordova": "^0.0.34" - }, - "dependencies": { - "@types/cordova": { - "version": "0.0.34", - "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", - "integrity": "sha512-rkiiTuf/z2wTd4RxFOb+clE7PF4AEJU0hsczbUdkHHBtkUmpWQpEddynNfJYKYtZFJKbq4F+brfekt1kx85IZA==" - } - } - }, "@ionic-native/qr-scanner": { "version": "5.36.0", "resolved": "https://registry.npmjs.org/@ionic-native/qr-scanner/-/qr-scanner-5.36.0.tgz", @@ -11588,10 +11573,33 @@ "resolved": "https://registry.npmjs.org/@moodlehq/cordova-plugin-zip/-/cordova-plugin-zip-3.1.0-moodle.1.tgz", "integrity": "sha512-QD5S6bsm6awJrNMb8YN/vkYghKAMfZMHccdimx6s1i5S9fgZUSf7L477NJqjFu62imVZYJIJuavBbw5fR/562w==" }, + "@moodlehq/ionic-native-push": { + "version": "5.36.0-moodle.2", + "resolved": "https://registry.npmjs.org/@moodlehq/ionic-native-push/-/ionic-native-push-5.36.0-moodle.2.tgz", + "integrity": "sha512-UWT4WaoTEEqGQ5pu+CyakXCOhiXsQSb8mD8j89jDqV0hJyrIQ8zA2ciGW9Y/vd55NuqjCu1tNJcWEJ4WcRVv0Q==", + "requires": { + "@angular/core": "^9.1.12", + "@ionic-native/core": "^5.1.0", + "@types/cordova": "^11.0.0", + "rxjs": "^5.5.0 || ^6.5.0" + }, + "dependencies": { + "@angular/core": { + "version": "9.1.13", + "resolved": "https://registry.npmjs.org/@angular/core/-/core-9.1.13.tgz", + "integrity": "sha512-mBm24Q9GjkAsxMAzqQ86U1078+yTEpr0+syMEruUtJ0HUH6Fzn3J+6xTLb+BVcGb9RkCkFaV9T5mcn6ZM0f++g==" + }, + "@types/cordova": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-11.0.0.tgz", + "integrity": "sha512-AtBm1IAqqXsXszJe6XxuA2iXLhraNCj25p/FHRyikPeW0Z3YfgM6qzWb+VJglJTmZc5lqRNy84cYM/sQI5v6Vw==" + } + } + }, "@moodlehq/phonegap-plugin-push": { - "version": "4.0.0-moodle.2", - "resolved": "https://registry.npmjs.org/@moodlehq/phonegap-plugin-push/-/phonegap-plugin-push-4.0.0-moodle.2.tgz", - "integrity": "sha512-kxHnpCzM7VMw5XUrLeZX03bLkQzA3j//+4nq7MiZbLoliPsQRAxGqyZ9HmbLcPsvlt1h7NM1eSVG52qZ7D3PlQ==" + "version": "4.0.0-moodle.3", + "resolved": "https://registry.npmjs.org/@moodlehq/phonegap-plugin-push/-/phonegap-plugin-push-4.0.0-moodle.3.tgz", + "integrity": "sha512-oJTmcVN6QBxo8+9uHEFTLCgNJkd7jeaT1MMM3ljDhR5EkFDkHwMMat/Km0tjm+9ToD0LYWHZfvLljpCZM5u3yg==" }, "@mrmlnc/readdir-enhanced": { "version": "2.2.1", diff --git a/package.json b/package.json index 2410b387a..f58b902a1 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,6 @@ "@ionic-native/local-notifications": "5.36.0", "@ionic-native/media-capture": "5.36.0", "@ionic-native/network": "5.36.0", - "@ionic-native/push": "5.36.0", "@ionic-native/qr-scanner": "5.36.0", "@ionic-native/splash-screen": "5.36.0", "@ionic-native/sqlite": "5.36.0", @@ -80,7 +79,8 @@ "@moodlehq/cordova-plugin-local-notification": "0.9.0-moodle.11", "@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.5", "@moodlehq/cordova-plugin-zip": "3.1.0-moodle.1", - "@moodlehq/phonegap-plugin-push": "4.0.0-moodle.2", + "@moodlehq/ionic-native-push": "5.36.0-moodle.2", + "@moodlehq/phonegap-plugin-push": "4.0.0-moodle.3", "@ngx-translate/core": "13.0.0", "@ngx-translate/http-loader": "6.0.0", "@types/chart.js": "2.9.31", diff --git a/src/core/features/native/native.module.ts b/src/core/features/native/native.module.ts index c0a82490f..ae1248de5 100644 --- a/src/core/features/native/native.module.ts +++ b/src/core/features/native/native.module.ts @@ -30,7 +30,7 @@ import { WebView } from '@ionic-native/ionic-webview/ngx'; import { Keyboard } from '@ionic-native/keyboard/ngx'; import { LocalNotifications } from '@ionic-native/local-notifications/ngx'; import { MediaCapture } from '@ionic-native/media-capture/ngx'; -import { Push } from '@ionic-native/push/ngx'; +import { Push } from '@moodlehq/ionic-native-push/ngx'; import { QRScanner } from '@ionic-native/qr-scanner/ngx'; import { SplashScreen } from '@ionic-native/splash-screen/ngx'; import { SQLite } from '@ionic-native/sqlite/ngx'; diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index 417ee3849..4d6534c83 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { ILocalNotification } from '@ionic-native/local-notifications'; -import { NotificationEventResponse, PushOptions, RegistrationEventResponse } from '@ionic-native/push/ngx'; +import { NotificationEventResponse, PushOptions, RegistrationEventResponse } from '@moodlehq/ionic-native-push/ngx'; import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; @@ -750,6 +750,33 @@ export class CorePushNotificationsProvider { // Remove pending unregisters for this site. await CoreUtils.ignoreErrors(this.pendingUnregistersTable.deleteByPrimaryKey({ siteid: site.getId() })); } + + this.registerPublicKeyOnMoodle(); + } + + /** + * Register a public key on a Moodle site. + */ + async registerPublicKeyOnMoodle(): Promise { + this.logger.debug('Register public key on Moodle.'); + + const site = await CoreSites.getSite(); + + const publicKey = await Push.getPublicKey(); + if (publicKey == null) { + throw new CoreError('Cannot get app public key.'); + } + + const data: CoreUserUpdateUserDevicePublicKeyWSParams = { + uuid: Device.uuid, + appid: CoreConstants.CONFIG.app_id, + publickey: publicKey, + }; + + await site.write( + 'core_user_update_user_device_public_key', + data, + ); } /** @@ -936,3 +963,20 @@ export type CoreUserAddUserDeviceWSParams = { * Data returned by core_user_add_user_device WS. */ export type CoreUserAddUserDeviceWSResponse = CoreWSExternalWarning[][]; + +/** + * Params of core_user_update_user_device_public_key WS. + */ +export type CoreUserUpdateUserDevicePublicKeyWSParams = { + uuid: string; + appid: string; + publickey: string; +}; + +/** + * Data returned by core_user_update_user_device_public_key WS. + */ +export type CoreUserUpdateUserDevicePublicKeyWSResponse = { + status: boolean; + warnings?: CoreWSExternalWarning[]; +}; diff --git a/src/core/singletons/index.ts b/src/core/singletons/index.ts index 60b71d369..5cad775d7 100644 --- a/src/core/singletons/index.ts +++ b/src/core/singletons/index.ts @@ -53,7 +53,7 @@ import { WebView as WebViewService } from '@ionic-native/ionic-webview/ngx'; import { Keyboard as KeyboardService } from '@ionic-native/keyboard/ngx'; import { LocalNotifications as LocalNotificationsService } from '@ionic-native/local-notifications/ngx'; import { MediaCapture as MediaCaptureService } from '@ionic-native/media-capture/ngx'; -import { Push as PushService } from '@ionic-native/push/ngx'; +import { Push as PushService } from '@moodlehq/ionic-native-push/ngx'; import { QRScanner as QRScannerService } from '@ionic-native/qr-scanner/ngx'; import { StatusBar as StatusBarService } from '@ionic-native/status-bar/ngx'; import { SplashScreen as SplashScreenService } from '@ionic-native/splash-screen/ngx';