From d530d2b95e9893fb8e2a1f56682134a59ce3cde4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 29 May 2019 17:19:53 +0200 Subject: [PATCH 1/6] MOBILE-3039 ios: Make avatars circled in shared files choose --- src/core/sharedfiles/pages/choose-site/choose-site.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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}}

From 136869cc04985a558f7327427e24dc082ab87685 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 29 May 2019 18:25:35 +0200 Subject: [PATCH 2/6] MOBILE-3039 push: Fix sync errors caused by pushnotifications --- .../providers/pushnotifications.ts | 13 +++++++++++-- .../providers/register-cron-handler.ts | 2 +- src/providers/utils/utils.ts | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index 3a48abfc7..430d78000 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. * @@ -658,7 +667,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 +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); 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/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))); } /** From 3eb0c81c462b6c0a647990646cb383b73a8dc2ab Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 30 May 2019 10:12:37 +0200 Subject: [PATCH 3/6] MOBILE-3039 core: Fix getStoredConfig error in synchronize --- src/core/mainmenu/pages/more/more.ts | 2 ++ src/providers/sites.ts | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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/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); }); } From 1ab815442822aabfb261ce59aa7ace9c3e494bb7 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 30 May 2019 12:20:07 +0200 Subject: [PATCH 4/6] MOBILE-3039 push: Fix appurl from push notifs in iOS --- src/core/pushnotifications/providers/pushnotifications.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index 430d78000..992a311be 100644 --- a/src/core/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -403,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()) { From b2c63f450382388d07a213621b2e5141d0d12527 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 30 May 2019 12:28:13 +0200 Subject: [PATCH 5/6] MOBILE-3039 core: Allow forcing offline mode from javascript console --- src/providers/app.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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; + } } From f4cd6f37b043644ba76d5ba898d1817fab283bb9 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 30 May 2019 13:35:28 +0200 Subject: [PATCH 6/6] MOBILE-3039 core: Fix old custom URL links in iOS --- src/providers/urlschemes.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) => {