MOBILE-3039 push: Fix sync errors caused by pushnotifications
parent
d530d2b95e
commit
136869cc04
|
@ -200,6 +200,15 @@ export class CorePushNotificationsProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the device can be registered in Moodle to receive push notifications.
|
||||
*
|
||||
* @return {boolean} Whether the device can be registered in Moodle.
|
||||
*/
|
||||
canRegisterOnMoodle(): boolean {
|
||||
return this.pushID && this.appProvider.isMobile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all badge records for a given site.
|
||||
*
|
||||
|
@ -658,7 +667,7 @@ export class CorePushNotificationsProvider {
|
|||
registerDeviceOnMoodle(siteId?: string, forceUnregister?: boolean): Promise<any> {
|
||||
this.logger.debug('Register device on Moodle.');
|
||||
|
||||
if (!this.pushID || !this.appProvider.isMobile()) {
|
||||
if (!this.canRegisterOnMoodle()) {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
|
||||
|
@ -729,7 +738,7 @@ export class CorePushNotificationsProvider {
|
|||
|
||||
if (siteId) {
|
||||
// Check if the site has a pending unregister.
|
||||
promise = this.appDB.getRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, {siteid: siteId});
|
||||
promise = this.appDB.getRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: siteId});
|
||||
} else {
|
||||
// Get all pending unregisters.
|
||||
promise = this.appDB.getAllRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE);
|
||||
|
|
|
@ -42,7 +42,7 @@ export class CorePushNotificationsRegisterCronHandler implements CoreCronHandler
|
|||
* @return {Promise<any>} Promise resolved when done, rejected if failure.
|
||||
*/
|
||||
execute(siteId?: string): Promise<any> {
|
||||
if (!siteId) {
|
||||
if (!siteId || !this.pushNotificationsProvider.canRegisterOnMoodle()) {
|
||||
// It's not a specific site, don't do anything.
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
|
@ -742,11 +742,11 @@ export class CoreUtilsProvider {
|
|||
* @return {boolean} Whether the error was returned by the WebService.
|
||||
*/
|
||||
isWebServiceError(error: any): boolean {
|
||||
return typeof error.warningcode != 'undefined' || (typeof error.errorcode != 'undefined' &&
|
||||
return error && (typeof error.warningcode != 'undefined' || (typeof error.errorcode != 'undefined' &&
|
||||
error.errorcode != 'invalidtoken' && error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
|
||||
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
|
||||
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
|
||||
(error.errorcode != 'accessexception' || error.message.indexOf('Invalid token - token expired') == -1));
|
||||
(error.errorcode != 'accessexception' || error.message.indexOf('Invalid token - token expired') == -1)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue