MOBILE-3039 push: Fix sync errors caused by pushnotifications

main
Dani Palou 2019-05-29 18:25:35 +02:00
parent d530d2b95e
commit 136869cc04
3 changed files with 14 additions and 5 deletions

View File

@ -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. * Delete all badge records for a given site.
* *
@ -658,7 +667,7 @@ export class CorePushNotificationsProvider {
registerDeviceOnMoodle(siteId?: string, forceUnregister?: boolean): Promise<any> { registerDeviceOnMoodle(siteId?: string, forceUnregister?: boolean): Promise<any> {
this.logger.debug('Register device on Moodle.'); this.logger.debug('Register device on Moodle.');
if (!this.pushID || !this.appProvider.isMobile()) { if (!this.canRegisterOnMoodle()) {
return Promise.reject(null); return Promise.reject(null);
} }
@ -729,7 +738,7 @@ export class CorePushNotificationsProvider {
if (siteId) { if (siteId) {
// Check if the site has a pending unregister. // 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 { } else {
// Get all pending unregisters. // Get all pending unregisters.
promise = this.appDB.getAllRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE); promise = this.appDB.getAllRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE);

View File

@ -42,7 +42,7 @@ export class CorePushNotificationsRegisterCronHandler implements CoreCronHandler
* @return {Promise<any>} Promise resolved when done, rejected if failure. * @return {Promise<any>} Promise resolved when done, rejected if failure.
*/ */
execute(siteId?: string): Promise<any> { execute(siteId?: string): Promise<any> {
if (!siteId) { if (!siteId || !this.pushNotificationsProvider.canRegisterOnMoodle()) {
// It's not a specific site, don't do anything. // It's not a specific site, don't do anything.
return Promise.resolve(); return Promise.resolve();
} }

View File

@ -742,11 +742,11 @@ export class CoreUtilsProvider {
* @return {boolean} Whether the error was returned by the WebService. * @return {boolean} Whether the error was returned by the WebService.
*/ */
isWebServiceError(error: any): boolean { 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 != 'invalidtoken' && error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' && error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' && 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)));
} }
/** /**