MOBILE-3833 core: Update handlers when user completes profile

main
Dani Palou 2022-04-13 15:38:13 +02:00
parent 1d05af2b7d
commit 7097d3c9fc
5 changed files with 44 additions and 13 deletions

View File

@ -175,7 +175,7 @@ export class AppComponent implements OnInit, AfterViewInit {
this.lastInAppUrl = '';
if (CoreLoginHelper.isWaitingForBrowser()) {
CoreLoginHelper.setWaitingForBrowser(false);
CoreLoginHelper.stopWaitingForBrowser();
CoreLoginHelper.checkLogout();
}
});
@ -184,7 +184,7 @@ export class AppComponent implements OnInit, AfterViewInit {
// Wait a second before setting it to false since in iOS there could be some frozen WS calls.
setTimeout(() => {
if (CoreLoginHelper.isWaitingForBrowser()) {
CoreLoginHelper.setWaitingForBrowser(false);
CoreLoginHelper.stopWaitingForBrowser();
CoreLoginHelper.checkLogout();
}
}, 1000);

View File

@ -103,6 +103,11 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
this.updateHandlers();
}
});
CoreEvents.on(CoreEvents.COMPLETE_REQUIRED_PROFILE_DATA_FINISHED, (data) => {
if (data.siteId === CoreSites.getCurrentSiteId()) {
this.updateHandlers();
}
});
}
}

View File

@ -37,6 +37,7 @@ import { CoreCanceledError } from '@classes/errors/cancelederror';
import { CoreCustomURLSchemes } from '@services/urlschemes';
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
import { CoreText } from '@singletons/text';
import { CorePromisedValue } from '@classes/promised-value';
/**
* Helper provider that provides some common features regarding authentication.
@ -56,7 +57,7 @@ export class CoreLoginHelperProvider {
protected logger: CoreLogger;
protected sessionExpiredCheckingSite: Record<string, boolean> = {};
protected isOpenEditAlertShown = false;
protected waitingForBrowser = false;
protected waitingForBrowser?: CorePromisedValue<void>;
constructor() {
this.logger = CoreLogger.getInstance('CoreLoginHelper');
@ -768,11 +769,15 @@ export class CoreLoginHelperProvider {
try {
await currentSite.openInAppWithAutoLogin(siteUrl + path, undefined, alertMessage);
this.waitingForBrowser = true;
} finally {
this.isOpenEditAlertShown = false;
}
await this.waitForBrowser();
CoreEvents.trigger(CoreEvents.COMPLETE_REQUIRED_PROFILE_DATA_FINISHED, {
path,
}, siteId);
}
}
@ -917,7 +922,7 @@ export class CoreLoginHelperProvider {
(currentSite.isLoggedOut() ? 'loggedoutssodescription' : 'reconnectssodescription')));
}
this.waitingForBrowser = true;
this.waitForBrowser();
this.openBrowserForSSOLogin(
result.siteUrl,
@ -950,7 +955,7 @@ export class CoreLoginHelperProvider {
try {
await CoreDomUtils.showConfirm(confirmMessage);
this.waitingForBrowser = true;
this.waitForBrowser();
CoreSites.unsetCurrentSite(); // Unset current site to make authentication work fine.
this.openBrowserForOAuthLogin(
@ -1223,16 +1228,28 @@ export class CoreLoginHelperProvider {
* @return Whether the app is waiting for browser.
*/
isWaitingForBrowser(): boolean {
return this.waitingForBrowser;
return !!this.waitingForBrowser;
}
/**
* Set whether the app is waiting for browser.
* Start waiting when opening a browser/IAB.
*
* @param value New value.
* @return Promise resolved when the app is resumed.
*/
setWaitingForBrowser(value: boolean): void {
this.waitingForBrowser = value;
async waitForBrowser(): Promise<void> {
if (!this.waitingForBrowser) {
this.waitingForBrowser = new CorePromisedValue();
}
await this.waitingForBrowser;
}
/**
* Stop waiting for browser.
*/
stopWaitingForBrowser(): void {
this.waitingForBrowser?.resolve();
this.waitingForBrowser = undefined;
}
/**

View File

@ -61,6 +61,7 @@ export interface CoreEventsData {
[CoreEvents.APP_LAUNCHED_URL]: CoreEventAppLaunchedData;
[CoreEvents.ORIENTATION_CHANGE]: CoreEventOrientationData;
[CoreEvents.COURSE_MODULE_VIEWED]: CoreEventCourseModuleViewed;
[CoreEvents.COMPLETE_REQUIRED_PROFILE_DATA_FINISHED]: CoreEventCompleteRequiredProfileDataFinished;
}
/*
@ -115,6 +116,7 @@ export class CoreEvents {
static readonly ACTIVITY_DATA_SENT = 'activity_data_sent';
static readonly DEVICE_REGISTERED_IN_MOODLE = 'device_registered_in_moodle';
static readonly COURSE_MODULE_VIEWED = 'course_module_viewed';
static readonly COMPLETE_REQUIRED_PROFILE_DATA_FINISHED = 'complete_required_profile_data_finished';
protected static logger = CoreLogger.getInstance('CoreEvents');
protected static observables: { [eventName: string]: Subject<unknown> } = {};
@ -467,3 +469,10 @@ export type CoreEventCourseModuleViewed = {
timeaccess: number;
sectionId?: number;
};
/**
* Data passed to COMPLETE_REQUIRED_PROFILE_DATA_FINISHED event.
*/
export type CoreEventCompleteRequiredProfileDataFinished = {
path: string;
};

View File

@ -25,7 +25,7 @@ information provided here is intended especially for developers.
- The variable "loaded" in CoreCourseModuleMainResourceComponent has been changed to "showLoading" to reflect its purpose better.
- The function getCurrentSection of course formats can now return a forceSelected boolean along with the section (defaults to false if not returned).
- The link handlers functions (CoreContentLinksHandler) will now always receive a relative URL instead of an absolute URL. The CoreContentLinksHandlerBase class now adds "^" to the start of the pattern by default to prevent false positives.
- The function CoreLoginHelper.setWaitingForBrowser has been removed, use CoreLoginHelper.waitForBrowser and CoreLoginHelper.stopWaitingForBrowser instead.
=== 3.9.5 ===