File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
core/pushnotifications/providers Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -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 *
@@ -658,7 +667,7 @@ export class CorePushNotificationsProvider {
658667 registerDeviceOnMoodle ( siteId ?: string , forceUnregister ?: boolean ) : Promise < any > {
659668 this . logger . debug ( 'Register device on Moodle.' ) ;
660669
661- if ( ! this . pushID || ! this . appProvider . isMobile ( ) ) {
670+ if ( ! this . canRegisterOnMoodle ( ) ) {
662671 return Promise . reject ( null ) ;
663672 }
664673
@@ -729,7 +738,7 @@ export class CorePushNotificationsProvider {
729738
730739 if ( siteId ) {
731740 // Check if the site has a pending unregister.
732- promise = this . appDB . getRecords ( CorePushNotificationsProvider . REGISTERED_DEVICES_TABLE , { siteid : siteId } ) ;
741+ promise = this . appDB . getRecords ( CorePushNotificationsProvider . PENDING_UNREGISTER_TABLE , { siteid : siteId } ) ;
733742 } else {
734743 // Get all pending unregisters.
735744 promise = this . appDB . getAllRecords ( CorePushNotificationsProvider . PENDING_UNREGISTER_TABLE ) ;
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export class CorePushNotificationsRegisterCronHandler implements CoreCronHandler
4242 * @return {Promise<any> } Promise resolved when done, rejected if failure.
4343 */
4444 execute ( siteId ?: string ) : Promise < any > {
45- if ( ! siteId ) {
45+ if ( ! siteId || ! this . pushNotificationsProvider . canRegisterOnMoodle ( ) ) {
4646 // It's not a specific site, don't do anything.
4747 return Promise . resolve ( ) ;
4848 }
Original file line number Diff line number Diff line change @@ -742,11 +742,11 @@ export class CoreUtilsProvider {
742742 * @return {boolean } Whether the error was returned by the WebService.
743743 */
744744 isWebServiceError ( error : any ) : boolean {
745- return typeof error . warningcode != 'undefined' || ( typeof error . errorcode != 'undefined' &&
745+ return error && ( typeof error . warningcode != 'undefined' || ( typeof error . errorcode != 'undefined' &&
746746 error . errorcode != 'invalidtoken' && error . errorcode != 'userdeleted' && error . errorcode != 'upgraderunning' &&
747747 error . errorcode != 'forcepasswordchangenotice' && error . errorcode != 'usernotfullysetup' &&
748748 error . errorcode != 'sitepolicynotagreed' && error . errorcode != 'sitemaintenance' &&
749- ( error . errorcode != 'accessexception' || error . message . indexOf ( 'Invalid token - token expired' ) == - 1 ) ) ;
749+ ( error . errorcode != 'accessexception' || error . message . indexOf ( 'Invalid token - token expired' ) == - 1 ) ) ) ;
750750 }
751751
752752 /**
You can’t perform that action at this time.
0 commit comments