@@ -200,6 +200,15 @@ export class CorePushNotificationsProvider {
200200 } ) ;
201201 }
202202
203+ /**
204+ * Check whether the device can be registered in Moodle to receive push notifications.
205+ *
206+ * @return {boolean } Whether the device can be registered in Moodle.
207+ */
208+ canRegisterOnMoodle ( ) : boolean {
209+ return this . pushID && this . appProvider . isMobile ( ) ;
210+ }
211+
203212 /**
204213 * Delete all badge records for a given site.
205214 *
@@ -394,6 +403,11 @@ export class CorePushNotificationsProvider {
394403 const data = notification ? notification . additionalData : { } ;
395404
396405 this . sitesProvider . getSite ( data . site ) . then ( ( ) => {
406+
407+ if ( typeof data . customdata == 'string' ) {
408+ data . customdata = this . textUtils . parseJSON ( data . customdata , { } ) ;
409+ }
410+
397411 if ( this . utils . isTrueOrOne ( data . foreground ) ) {
398412 // If the app is in foreground when the notification is received, it's not shown. Let's show it ourselves.
399413 if ( this . localNotificationsProvider . isAvailable ( ) ) {
@@ -658,7 +672,7 @@ export class CorePushNotificationsProvider {
658672 registerDeviceOnMoodle ( siteId ?: string , forceUnregister ?: boolean ) : Promise < any > {
659673 this . logger . debug ( 'Register device on Moodle.' ) ;
660674
661- if ( ! this . pushID || ! this . appProvider . isMobile ( ) ) {
675+ if ( ! this . canRegisterOnMoodle ( ) ) {
662676 return Promise . reject ( null ) ;
663677 }
664678
@@ -729,7 +743,7 @@ export class CorePushNotificationsProvider {
729743
730744 if ( siteId ) {
731745 // Check if the site has a pending unregister.
732- promise = this . appDB . getRecords ( CorePushNotificationsProvider . REGISTERED_DEVICES_TABLE , { siteid : siteId } ) ;
746+ promise = this . appDB . getRecords ( CorePushNotificationsProvider . PENDING_UNREGISTER_TABLE , { siteid : siteId } ) ;
733747 } else {
734748 // Get all pending unregisters.
735749 promise = this . appDB . getAllRecords ( CorePushNotificationsProvider . PENDING_UNREGISTER_TABLE ) ;
0 commit comments