diff --git a/src/core/mainmenu/pages/more/more.ts b/src/core/mainmenu/pages/more/more.ts index 03fc83452..c91d984bb 100644 --- a/src/core/mainmenu/pages/more/more.ts +++ b/src/core/mainmenu/pages/more/more.ts @@ -72,6 +72,8 @@ export class CoreMainMenuMorePage implements OnDestroy { */ ngOnDestroy(): void { window.removeEventListener('resize', this.initHandlers.bind(this)); + this.langObserver && this.langObserver.off(); + this.updateSiteObserver && this.updateSiteObserver.off(); if (this.subscription) { this.subscription.unsubscribe(); diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index 3a48abfc7..992a311be 100644 --- a/src/core/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -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. * @@ -394,6 +403,11 @@ export class CorePushNotificationsProvider { const data = notification ? notification.additionalData : {}; this.sitesProvider.getSite(data.site).then(() => { + + if (typeof data.customdata == 'string') { + data.customdata = this.textUtils.parseJSON(data.customdata, {}); + } + if (this.utils.isTrueOrOne(data.foreground)) { // If the app is in foreground when the notification is received, it's not shown. Let's show it ourselves. if (this.localNotificationsProvider.isAvailable()) { @@ -658,7 +672,7 @@ export class CorePushNotificationsProvider { registerDeviceOnMoodle(siteId?: string, forceUnregister?: boolean): Promise { this.logger.debug('Register device on Moodle.'); - if (!this.pushID || !this.appProvider.isMobile()) { + if (!this.canRegisterOnMoodle()) { return Promise.reject(null); } @@ -729,7 +743,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); diff --git a/src/core/pushnotifications/providers/register-cron-handler.ts b/src/core/pushnotifications/providers/register-cron-handler.ts index 0f04874b5..e2bc48b2c 100644 --- a/src/core/pushnotifications/providers/register-cron-handler.ts +++ b/src/core/pushnotifications/providers/register-cron-handler.ts @@ -42,7 +42,7 @@ export class CorePushNotificationsRegisterCronHandler implements CoreCronHandler * @return {Promise} Promise resolved when done, rejected if failure. */ execute(siteId?: string): Promise { - if (!siteId) { + if (!siteId || !this.pushNotificationsProvider.canRegisterOnMoodle()) { // It's not a specific site, don't do anything. return Promise.resolve(); } diff --git a/src/core/sharedfiles/pages/choose-site/choose-site.html b/src/core/sharedfiles/pages/choose-site/choose-site.html index eab31f622..ca01e2cb3 100644 --- a/src/core/sharedfiles/pages/choose-site/choose-site.html +++ b/src/core/sharedfiles/pages/choose-site/choose-site.html @@ -10,10 +10,12 @@

{{ 'core.sharedfiles.chooseaccountstorefile' | translate }}

{{fileName}}

- - + + + {{ 'core.pictureof' | translate:{$a: site.fullname} }} +

{{site.fullName}}

-

+

{{site.siteUrl}}

diff --git a/src/providers/app.ts b/src/providers/app.ts index 50deda52a..abbf4dd9f 100644 --- a/src/providers/app.ts +++ b/src/providers/app.ts @@ -73,6 +73,7 @@ export class CoreAppProvider { protected backActions = []; protected mainMenuId = 0; protected mainMenuOpen: number; + protected forceOffline = false; constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard, private appCtrl: App, private network: Network, logger: CoreLoggerProvider, private events: CoreEventsProvider, zone: NgZone, @@ -102,6 +103,9 @@ export class CoreAppProvider { this.platform.registerBackButtonAction(() => { this.backButtonAction(); }, 100); + + // Export the app provider so Behat tests can change the forceOffline flag. + ( window).appProvider = this; } /** @@ -257,6 +261,10 @@ export class CoreAppProvider { * @return {boolean} Whether the app is online. */ isOnline(): boolean { + if (this.forceOffline) { + return false; + } + let online = this.network.type !== null && this.network.type != Connection.NONE && this.network.type != Connection.UNKNOWN; // Double check we are not online because we cannot rely 100% in Cordova APIs. Also, check it in browser. if (!online && navigator.onLine) { @@ -567,4 +575,13 @@ export class CoreAppProvider { this.statusBar.styleLightContent() : this.statusBar.styleDefault(); } } + + /** + * Set value of forceOffline flag. If true, the app will think the device is offline. + * + * @param {boolean} value Value to set. + */ + setForceOffline(value: boolean): void { + this.forceOffline = !!value; + } } diff --git a/src/providers/sites.ts b/src/providers/sites.ts index 19f117a6a..b64da98fd 100644 --- a/src/providers/sites.ts +++ b/src/providers/sites.ts @@ -27,6 +27,7 @@ import { CoreConfigConstants } from '../configconstants'; import { CoreSite } from '@classes/site'; import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; import { Md5 } from 'ts-md5/dist/md5'; +import { Location } from '@angular/common'; /** * Response of checking if a site exists and its configuration. @@ -320,7 +321,7 @@ export class CoreSitesProvider { constructor(logger: CoreLoggerProvider, private http: HttpClient, private sitesFactory: CoreSitesFactoryProvider, private appProvider: CoreAppProvider, private translate: TranslateService, private urlUtils: CoreUrlUtilsProvider, - private eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider, + private eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider, private location: Location, private utils: CoreUtilsProvider) { this.logger = logger.getInstance('CoreSitesProvider'); @@ -1161,6 +1162,9 @@ export class CoreSitesProvider { promises.push(this.appDB.deleteRecords(this.CURRENT_SITE_TABLE, { id: 1 })); return Promise.all(promises).finally(() => { + // Due to DeepLinker, we need to remove the path from the URL, otherwise some pages are re-created when they shouldn't. + this.location.replaceState(''); + this.eventsProvider.trigger(CoreEventsProvider.LOGOUT, {}, siteId); }); } diff --git a/src/providers/urlschemes.ts b/src/providers/urlschemes.ts index 6617e627e..83b189c3a 100644 --- a/src/providers/urlschemes.ts +++ b/src/providers/urlschemes.ts @@ -125,10 +125,6 @@ export class CoreCustomURLSchemesProvider { // Some sites add a # at the end of the URL. If it's there, remove it. url = url.replace(/\/?#?\/?$/, ''); - // In iOS, the protocol after the scheme doesn't have ":". Add it. - // E.g. "moodlemobile://https://..." is received as "moodlemobile://https//..." - url = url.replace(/\/\/(https?)\/\//, '//$1://'); - modal = this.domUtils.showModalLoading(); // Get the data from the URL. @@ -137,8 +133,14 @@ export class CoreCustomURLSchemesProvider { return this.getCustomURLTokenData(url); } else if (this.isCustomURLLink(url)) { + // In iOS, the protocol after the scheme doesn't have ":". Add it. + url = url.replace(/\/\/link=(https?)\/\//, '//link=$1://'); + return this.getCustomURLLinkData(url); } else { + // In iOS, the protocol after the scheme doesn't have ":". Add it. + url = url.replace(/\/\/(https?)\/\//, '//$1://'); + return this.getCustomURLData(url); } }).then((result) => { diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts index d3d09bf47..e1595c75b 100644 --- a/src/providers/utils/utils.ts +++ b/src/providers/utils/utils.ts @@ -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))); } /**