MOBILE-3906 core: Update handlers after accepting site policy

main
Dani Palou 2021-11-05 09:37:29 +01:00
parent 13509e6683
commit aae810d1ad
4 changed files with 18 additions and 2 deletions

View File

@ -16,6 +16,7 @@ import { BehaviorSubject, Subject } from 'rxjs';
import { CoreEvents } from '@singletons/events';
import { CoreDelegate, CoreDelegateDisplayHandler, CoreDelegateToDisplay } from './delegate';
import { CoreUtils } from '@services/utils/utils';
import { CoreSites } from '@services/sites';
/**
* Superclass to help creating sorted delegates.
@ -39,6 +40,12 @@ export class CoreSortedDelegate<
super(delegateName, true);
CoreEvents.on(CoreEvents.LOGOUT, this.clearSortedHandlers.bind(this));
CoreEvents.on(CoreEvents.SITE_POLICY_AGREED, (data) => {
if (data.siteId === CoreSites.getCurrentSiteId()) {
// Clear loaded handlers when policy is agreed. The CoreDelegate class will load them again.
this.clearSortedHandlers();
}
});
}
/**

View File

@ -98,6 +98,11 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
CoreEvents.on(CoreEvents.LOGIN, this.updateHandlers.bind(this));
CoreEvents.on(CoreEvents.SITE_UPDATED, this.updateHandlers.bind(this));
CoreEvents.on(CoreEvents.SITE_PLUGINS_LOADED, this.updateHandlers.bind(this));
CoreEvents.on(CoreEvents.SITE_POLICY_AGREED, (data) => {
if (data.siteId === CoreSites.getCurrentSiteId()) {
this.updateHandlers();
}
});
}
}
@ -245,14 +250,14 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
const currentSite = CoreSites.getCurrentSite();
let promise: Promise<boolean>;
if (this.updatePromises[siteId] && this.updatePromises[siteId][handler.name]) {
if (this.updatePromises[siteId] && this.updatePromises[siteId][handler.name] !== undefined) {
// There's already an update ongoing for this handler, return the promise.
return this.updatePromises[siteId][handler.name];
} else if (!this.updatePromises[siteId]) {
this.updatePromises[siteId] = {};
}
if (!CoreSites.isLoggedIn() || this.isFeatureDisabled(handler, currentSite!)) {
if (!currentSite || this.isFeatureDisabled(handler, currentSite)) {
promise = Promise.resolve(false);
} else {
promise = Promise.resolve(handler.isEnabled()).catch(() => false);

View File

@ -21,6 +21,7 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreLoginHelper } from '@features/login/services/login-helper';
import { CoreSite } from '@classes/site';
import { CoreNavigator } from '@services/navigator';
import { CoreEvents } from '@singletons/events';
/**
* Page to accept a site policy.
@ -120,6 +121,8 @@ export class CoreLoginSitePolicyPage implements OnInit {
// Invalidate cache since some WS don't return error if site policy is not accepted.
await CoreUtils.ignoreErrors(this.currentSite.invalidateWsCache());
CoreEvents.trigger(CoreEvents.SITE_POLICY_AGREED, {}, this.siteId);
await CoreNavigator.navigateToSiteHome();
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'Error accepting site policy.');

View File

@ -67,6 +67,7 @@ export class CoreEvents {
static readonly SESSION_EXPIRED = 'session_expired';
static readonly PASSWORD_CHANGE_FORCED = 'password_change_forced';
static readonly USER_NOT_FULLY_SETUP = 'user_not_fully_setup';
static readonly SITE_POLICY_AGREED = 'site_policy_agreed';
static readonly SITE_POLICY_NOT_AGREED = 'site_policy_not_agreed';
static readonly LOGIN = 'login';
static readonly LOGOUT = 'logout';