diff --git a/scripts/langindex.json b/scripts/langindex.json index 65f618eaa..959e74ac0 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -2349,6 +2349,7 @@ "core.settings.enablefirebaseanalyticsdescription": "local_moodlemobileapp", "core.settings.enablerichtexteditor": "local_moodlemobileapp", "core.settings.enablerichtexteditordescription": "local_moodlemobileapp", + "core.settings.encryptedpushsupported": "local_moodlemobileapp", "core.settings.entriesincache": "local_moodlemobileapp", "core.settings.estimatedfreespace": "local_moodlemobileapp", "core.settings.filesystemroot": "local_moodlemobileapp", diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index dc8a499b8..234e54825 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -726,7 +726,7 @@ export class CorePushNotificationsProvider { try { const data = this.getRequiredRegisterData(); - data.publickey = await this.getPublicKey(site); + data.publickey = await this.getPublicKeyForSite(site); const neededActions = await this.getRegisterDeviceActions(data, site, forceUnregister); @@ -780,11 +780,24 @@ export class CorePushNotificationsProvider { * @param site Site to register * @returns Public key, undefined if the site or the device doesn't support encryption. */ - protected async getPublicKey(site: CoreSite): Promise { + protected async getPublicKeyForSite(site: CoreSite): Promise { if (!site.wsAvailable('core_user_update_user_device_public_key')) { return; } + return await this.getPublicKey(); + } + + /** + * Get the device public key. + * + * @returns Public key, undefined if the device doesn't support encryption. + */ + async getPublicKey(): Promise { + if (!CorePlatform.isMobile()) { + return; + } + const publicKey = await Push.getPublicKey(); return publicKey ?? undefined; diff --git a/src/core/features/settings/lang.json b/src/core/features/settings/lang.json index 1a6550718..db8630f5f 100644 --- a/src/core/features/settings/lang.json +++ b/src/core/features/settings/lang.json @@ -37,6 +37,7 @@ "enablefirebaseanalyticsdescription": "If enabled, the app will collect anonymous data usage.", "enablerichtexteditor": "Enable text editor", "enablerichtexteditordescription": "If enabled, a text editor will be available when entering content.", + "encryptedpushsupported": "Encrypted push notifications supported", "entriesincache": "{{$a}} entries in cache", "estimatedfreespace": "Estimated free space", "filesystemroot": "File system root", diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.html b/src/core/features/settings/pages/deviceinfo/deviceinfo.html index 22ee220d5..be13897a2 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.html +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.html @@ -148,6 +148,13 @@

{{ deviceInfo.pushId }}

+ + +

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

+

{{ 'core.no' | translate }}

+

{{ 'core.yes' | translate }}

+
+

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

diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts index 7db0a83fc..b1b6d3cf3 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts @@ -58,6 +58,7 @@ interface CoreSettingsDeviceInfo { uuid?: string; pushId?: string; localNotifAvailable: string; + encryptedPushSupported?: boolean; } /** @@ -210,6 +211,11 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { const showDevOptionsOnConfig = await CoreConfig.get('showDevOptions', 0); this.devOptionsForced = CoreConstants.BUILD.isDevelopment || CoreConstants.BUILD.isTesting; this.showDevOptions = this.devOptionsForced || showDevOptionsOnConfig == 1; + + const publicKey = this.deviceInfo.pushId ? + await CoreUtils.ignoreErrors(CorePushNotifications.getPublicKey()) : + undefined; + this.deviceInfo.encryptedPushSupported = publicKey !== undefined; } /**