Skip to content

Commit 136869c

Browse files
committed
MOBILE-3039 push: Fix sync errors caused by pushnotifications
1 parent d530d2b commit 136869c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/core/pushnotifications/providers/pushnotifications.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff 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);

src/core/pushnotifications/providers/register-cron-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

src/providers/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
/**

0 commit comments

Comments
 (0)