From 1a01d7da331bf6761fb1b2c52139d65f2b674c98 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 29 May 2019 13:14:09 +0200 Subject: [PATCH 1/3] MOBILE-3039 book: Fix check automatic completion --- src/addon/mod/book/components/index/index.ts | 2 +- src/addon/mod/forum/pages/discussion/discussion.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/addon/mod/book/components/index/index.ts b/src/addon/mod/book/components/index/index.ts index 1dd820508..1b154d373 100644 --- a/src/addon/mod/book/components/index/index.ts +++ b/src/addon/mod/book/components/index/index.ts @@ -186,7 +186,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp // Chapter loaded, log view. We don't return the promise because we don't want to block the user for this. this.bookProvider.logView(this.module.instance, chapterId, this.module.name).then(() => { // Module is completed when last chapter is viewed, so we only check completion if the last is reached. - if (!this.nextChapter) { + if (this.nextChapter == '0') { this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } }).catch(() => { diff --git a/src/addon/mod/forum/pages/discussion/discussion.ts b/src/addon/mod/forum/pages/discussion/discussion.ts index 2d6b9af79..f8514dd5f 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.ts +++ b/src/addon/mod/forum/pages/discussion/discussion.ts @@ -342,7 +342,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { this.accessInfo = {}; }).then(() => { this.defaultSubject = this.translate.instant('addon.mod_forum.re') + ' ' + - (this.discussion ? this.discussion.subject : ""); + (this.discussion ? this.discussion.subject : ''); this.replyData.subject = this.defaultSubject; const startingPost = this.forumProvider.extractStartingPost(posts); From a68b9a61b82a23be880fce85c3070a744b7ea744 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 29 May 2019 15:07:54 +0200 Subject: [PATCH 2/3] MOBILE-3039 core: Fix URL scheme launched when it shouldn't --- config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/config.xml b/config.xml index b2055031e..57488f7ba 100644 --- a/config.xml +++ b/config.xml @@ -37,6 +37,7 @@ + From d0beca075a279630ee02c4e5f26c8836eff80a1e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 29 May 2019 15:24:43 +0200 Subject: [PATCH 3/3] MOBILE-3039 core: Fix reconnect screen shown again when it shouldn't --- src/classes/site.ts | 2 ++ src/providers/sites.ts | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/classes/site.ts b/src/classes/site.ts index afafeada4..9253f83e6 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -680,6 +680,8 @@ export class CoreSite { (error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) { if (initialToken !== this.token && !retrying) { // Token has changed, retry with the new token. + preSets.getFromCache = false; // Don't check cache now. Also, it will skip ongoingRequests. + return this.request(method, data, preSets, true); } else if (this.appProvider.isSSOAuthenticationOngoing()) { // There's an SSO authentication ongoing, wait for it to finish and try again. diff --git a/src/providers/sites.ts b/src/providers/sites.ts index de7424c1b..19f117a6a 100644 --- a/src/providers/sites.ts +++ b/src/providers/sites.ts @@ -582,22 +582,48 @@ export class CoreSitesProvider { } // Create a "candidate" site to fetch the site info. - const candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken); + let candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken), + isNewSite = true; return candidateSite.fetchSiteInfo().then((info) => { const result = this.isValidMoodleVersion(info); if (result == this.VALID_VERSION) { - // Set site ID and info. const siteId = this.createSiteID(info.siteurl, info.username); - candidateSite.setId(siteId); - candidateSite.setInfo(info); - // Create database tables before login and before any WS call. - return this.migrateSiteSchemas(candidateSite).then(() => { + // Check if the site already exists. + return this.getSite(siteId).catch(() => { + // Not exists. + }).then((site) => { + if (site) { + // Site already exists, update its data and use it. + isNewSite = false; + candidateSite = site; + candidateSite.setToken(token); + candidateSite.setPrivateToken(privateToken); + candidateSite.setInfo(info); + + } else { + // New site, set site ID and info. + isNewSite = true; + candidateSite.setId(siteId); + candidateSite.setInfo(info); + + // Create database tables before login and before any WS call. + return this.migrateSiteSchemas(candidateSite); + } + + }).then(() => { // Try to get the site config. - return this.getSiteConfig(candidateSite).then((config) => { - candidateSite.setConfig(config); + return this.getSiteConfig(candidateSite).catch((error) => { + // Ignore errors if it's not a new site, we'll use the config already stored. + if (isNewSite) { + return Promise.reject(error); + } + }).then((config) => { + if (typeof config != 'undefined') { + candidateSite.setConfig(config); + } // Add site to sites list. this.addSite(siteId, siteUrl, token, info, privateToken, config);