MOBILE-4538 delegates: Add handlers promise enabled info and remove code
parent
ebbfe039c0
commit
21b43d56df
|
@ -75,7 +75,7 @@ export class AddonMessageOutputDelegateService extends CoreDelegate<AddonMessage
|
|||
protected handlerNameProperty = 'processorName';
|
||||
|
||||
constructor() {
|
||||
super('AddonMessageOutputDelegate', true);
|
||||
super('AddonMessageOutputDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -185,7 +185,7 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate<AddonMod
|
|||
constructor(
|
||||
protected defaultHandler: AddonModAssignDefaultFeedbackHandler,
|
||||
) {
|
||||
super('AddonModAssignFeedbackDelegate', true);
|
||||
super('AddonModAssignFeedbackDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -277,7 +277,7 @@ export class AddonModAssignSubmissionDelegateService extends CoreDelegate<AddonM
|
|||
constructor(
|
||||
protected defaultHandler: AddonModAssignDefaultSubmissionHandler,
|
||||
) {
|
||||
super('AddonModAssignSubmissionDelegate', true);
|
||||
super('AddonModAssignSubmissionDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -132,7 +132,7 @@ export class AddonModDataFieldsDelegateService extends CoreDelegate<AddonModData
|
|||
constructor(
|
||||
protected defaultHandler: AddonModDataDefaultFieldHandler,
|
||||
) {
|
||||
super('AddonModDataFieldsDelegate', true);
|
||||
super('AddonModDataFieldsDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -128,7 +128,7 @@ export class AddonModQuizAccessRuleDelegateService extends CoreDelegate<AddonMod
|
|||
protected handlerNameProperty = 'ruleName';
|
||||
|
||||
constructor() {
|
||||
super('AddonModQuizAccessRulesDelegate', true);
|
||||
super('AddonModQuizAccessRulesDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -83,7 +83,7 @@ export class AddonWorkshopAssessmentStrategyDelegateService extends CoreDelegate
|
|||
protected handlerNameProperty = 'strategyName';
|
||||
|
||||
constructor() {
|
||||
super('AddonWorkshopAssessmentStrategyDelegate', true);
|
||||
super('AddonWorkshopAssessmentStrategyDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,7 +34,7 @@ export class CoreSortedDelegate<
|
|||
* @inheritdoc
|
||||
*/
|
||||
constructor(delegateName: string) {
|
||||
super(delegateName, true);
|
||||
super(delegateName);
|
||||
|
||||
CoreEvents.on(CoreEvents.LOGOUT, () => this.clearSortedHandlers());
|
||||
CoreEvents.on(CoreEvents.SITE_POLICY_AGREED, (data) => {
|
||||
|
|
|
@ -72,28 +72,28 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
|
|||
|
||||
/**
|
||||
* Promise to wait for handlers to be initialized.
|
||||
*
|
||||
* @returns Promise resolved when handlers are enabled.
|
||||
*/
|
||||
protected handlersInitPromise: Promise<void>;
|
||||
protected handlersInitPromise: Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Function to resolve the handlers init promise.
|
||||
*/
|
||||
protected handlersInitResolve!: () => void;
|
||||
protected handlersInitResolve!: (enabled: boolean) => void;
|
||||
|
||||
/**
|
||||
* Constructor of the Delegate.
|
||||
*
|
||||
* @param delegateName Delegate name used for logging purposes.
|
||||
* @param listenSiteEvents Whether to update the handler when a site event occurs (login, site updated, ...).
|
||||
*/
|
||||
constructor(delegateName: string, listenSiteEvents: boolean = true) {
|
||||
constructor(delegateName: string) {
|
||||
this.logger = CoreLogger.getInstance(delegateName);
|
||||
|
||||
this.handlersInitPromise = new Promise((resolve): void => {
|
||||
this.handlersInitResolve = resolve;
|
||||
});
|
||||
|
||||
if (listenSiteEvents) {
|
||||
// Update handlers on this cases.
|
||||
CoreEvents.on(CoreEvents.LOGIN, () => this.updateHandlers());
|
||||
CoreEvents.on(CoreEvents.SITE_UPDATED, () => this.updateHandlers());
|
||||
|
@ -109,7 +109,6 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the delegate is enabled so handlers are not updated if not..
|
||||
|
@ -286,9 +285,12 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
|
|||
}
|
||||
|
||||
// Checks if the handler is enabled.
|
||||
this.updatePromises[siteId][handler.name] = promise.then((enabled: boolean) => {
|
||||
this.updatePromises[siteId][handler.name] = promise.then((enabled) => {
|
||||
// Check that site hasn't changed since the check started.
|
||||
if (CoreSites.getCurrentSiteId() === siteId) {
|
||||
if (CoreSites.getCurrentSiteId() !== siteId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const key = handler[this.handlerNameProperty] || handler.name;
|
||||
|
||||
if (enabled) {
|
||||
|
@ -296,7 +298,6 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
|
|||
} else {
|
||||
delete this.enabledHandlers[key];
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}).finally(() => {
|
||||
|
@ -327,6 +328,10 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
|
|||
const enabled = await this.isEnabled();
|
||||
|
||||
if (!enabled) {
|
||||
this.logger.debug('Delegate not enabled.');
|
||||
|
||||
this.handlersInitResolve(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -351,7 +356,7 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
|
|||
// Verify that this call is the last one that was started.
|
||||
if (this.isLastUpdateCall(now)) {
|
||||
this.handlersInitialized = true;
|
||||
this.handlersInitResolve();
|
||||
this.handlersInitResolve(true);
|
||||
|
||||
this.updateData();
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ export class CoreBlockDelegateService extends CoreDelegate<CoreBlockHandler> {
|
|||
constructor(
|
||||
protected defaultHandler: CoreBlockDefaultHandler,
|
||||
) {
|
||||
super('CoreBlockDelegate', true);
|
||||
super('CoreBlockDelegate');
|
||||
|
||||
this.blocksUpdateObservable = new Subject<void>();
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate<CoreCourseForm
|
|||
protected handlerNameProperty = 'format';
|
||||
|
||||
constructor(protected defaultHandler: CoreCourseFormatDefaultHandler) {
|
||||
super('CoreCoursesCourseFormatDelegate', true);
|
||||
super('CoreCoursesCourseFormatDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -286,7 +286,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
|
|||
protected handlerNameProperty = 'modName';
|
||||
|
||||
constructor(protected defaultHandler: CoreCourseModuleDefaultHandler) {
|
||||
super('CoreCourseModuleDelegate', true);
|
||||
super('CoreCourseModuleDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,7 +54,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
protected prefetchData: Record<string, Record<string, OngoingPrefetch>> = {};
|
||||
|
||||
constructor() {
|
||||
super('CoreCourseModulePrefetchDelegate', true);
|
||||
super('CoreCourseModulePrefetchDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -129,7 +129,7 @@ export class CoreEnrolDelegateService extends CoreDelegate<CoreEnrolHandler> {
|
|||
protected featurePrefix = 'CoreEnrolDelegate_';
|
||||
|
||||
constructor() {
|
||||
super('CoreEnrolDelegate', true);
|
||||
super('CoreEnrolDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -143,7 +143,7 @@ export interface CoreFileUploaderHandlerDataToReturn extends CoreFileUploaderHan
|
|||
export class CoreFileUploaderDelegateService extends CoreDelegate<CoreFileUploaderHandler> {
|
||||
|
||||
constructor() {
|
||||
super('CoreFileUploaderDelegate', true);
|
||||
super('CoreFileUploaderDelegate');
|
||||
|
||||
CoreEvents.on(CoreEvents.LOGOUT, () => this.clearSiteHandlers());
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ export class CoreFilterDelegateService extends CoreDelegate<CoreFilterHandler> {
|
|||
protected handlerNameProperty = 'filterName';
|
||||
|
||||
constructor(protected defaultHandler: CoreFilterDefaultHandler) {
|
||||
super('CoreFilterDelegate', true);
|
||||
super('CoreFilterDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,7 +68,7 @@ export class CoreQuestionBehaviourDelegateService extends CoreDelegate<CoreQuest
|
|||
protected handlerNameProperty = 'type';
|
||||
|
||||
constructor(protected defaultHandler: CoreQuestionBehaviourDefaultHandler) {
|
||||
super('CoreQuestionBehaviourDelegate', true);
|
||||
super('CoreQuestionBehaviourDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -217,7 +217,7 @@ export class CoreQuestionDelegateService extends CoreDelegate<CoreQuestionHandle
|
|||
protected handlerNameProperty = 'type';
|
||||
|
||||
constructor(protected defaultHandler: CoreQuestionDefaultHandler) {
|
||||
super('CoreQuestionDelegate', true);
|
||||
super('CoreQuestionDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,7 @@ export class CoreTagAreaDelegateService extends CoreDelegate<CoreTagAreaHandler>
|
|||
protected handlerNameProperty = 'type';
|
||||
|
||||
constructor() {
|
||||
super('CoreTagAreaDelegate', true);
|
||||
super('CoreTagAreaDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -229,7 +229,7 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
|
|||
protected userHandlers: Record<number, Record<string, CoreUserDelegateHandlersData>> = {};
|
||||
|
||||
constructor() {
|
||||
super('CoreUserDelegate', true);
|
||||
super('CoreUserDelegate');
|
||||
|
||||
CoreEvents.on(USER_DELEGATE_UPDATE_HANDLER_EVENT, (data) => {
|
||||
const handlersData = this.getHandlersData(data.userId, data.context, data.contextId);
|
||||
|
|
|
@ -80,7 +80,7 @@ export class CoreUserProfileFieldDelegateService extends CoreDelegate<CoreUserPr
|
|||
protected handlerNameProperty = 'type';
|
||||
|
||||
constructor() {
|
||||
super('CoreUserProfileFieldDelegate', true);
|
||||
super('CoreUserProfileFieldDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ import { CoreTextUtils } from '@services/utils/text';
|
|||
export class CoreAnalyticsService extends CoreDelegate<CoreAnalyticsHandler> {
|
||||
|
||||
constructor() {
|
||||
super('CoreAnalyticsService', true);
|
||||
super('CoreAnalyticsService');
|
||||
|
||||
CoreEvents.on(CoreConfigProvider.ENVIRONMENT_UPDATED, () => this.updateHandlers());
|
||||
CoreEvents.on(CoreEvents.LOGOUT, () => this.clearSiteHandlers());
|
||||
|
|
|
@ -30,7 +30,7 @@ import { CoreFileHelper } from './file-helper';
|
|||
export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHandler> {
|
||||
|
||||
constructor() {
|
||||
super('CorePluginFileDelegate', true);
|
||||
super('CorePluginFileDelegate');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue