forked from EVOgeek/Vmeda.Online
		
	MOBILE-3039 core: Fix reconnect screen shown again when it shouldn't
This commit is contained in:
		
							parent
							
								
									a68b9a61b8
								
							
						
					
					
						commit
						d0beca075a
					
				@ -680,6 +680,8 @@ export class CoreSite {
 | 
				
			|||||||
                    (error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) {
 | 
					                    (error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) {
 | 
				
			||||||
                    if (initialToken !== this.token && !retrying) {
 | 
					                    if (initialToken !== this.token && !retrying) {
 | 
				
			||||||
                        // Token has changed, retry with the new token.
 | 
					                        // 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);
 | 
					                        return this.request(method, data, preSets, true);
 | 
				
			||||||
                    } else if (this.appProvider.isSSOAuthenticationOngoing()) {
 | 
					                    } else if (this.appProvider.isSSOAuthenticationOngoing()) {
 | 
				
			||||||
                        // There's an SSO authentication ongoing, wait for it to finish and try again.
 | 
					                        // There's an SSO authentication ongoing, wait for it to finish and try again.
 | 
				
			||||||
 | 
				
			|||||||
@ -582,22 +582,48 @@ export class CoreSitesProvider {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create a "candidate" site to fetch the site info.
 | 
					        // 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) => {
 | 
					        return candidateSite.fetchSiteInfo().then((info) => {
 | 
				
			||||||
            const result = this.isValidMoodleVersion(info);
 | 
					            const result = this.isValidMoodleVersion(info);
 | 
				
			||||||
            if (result == this.VALID_VERSION) {
 | 
					            if (result == this.VALID_VERSION) {
 | 
				
			||||||
                // Set site ID and info.
 | 
					 | 
				
			||||||
                const siteId = this.createSiteID(info.siteurl, info.username);
 | 
					                const siteId = this.createSiteID(info.siteurl, info.username);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 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.setId(siteId);
 | 
				
			||||||
                        candidateSite.setInfo(info);
 | 
					                        candidateSite.setInfo(info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // Create database tables before login and before any WS call.
 | 
					                        // Create database tables before login and before any WS call.
 | 
				
			||||||
                return this.migrateSiteSchemas(candidateSite).then(() => {
 | 
					                        return this.migrateSiteSchemas(candidateSite);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                }).then(() => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // Try to get the site config.
 | 
					                    // Try to get the site config.
 | 
				
			||||||
                    return this.getSiteConfig(candidateSite).then((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);
 | 
					                            candidateSite.setConfig(config);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // Add site to sites list.
 | 
					                        // Add site to sites list.
 | 
				
			||||||
                        this.addSite(siteId, siteUrl, token, info, privateToken, config);
 | 
					                        this.addSite(siteId, siteUrl, token, info, privateToken, config);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user