diff --git a/src/core/classes/delegate-sorted.ts b/src/core/classes/delegate-sorted.ts index 41f9fdc5c..ea4e99cce 100644 --- a/src/core/classes/delegate-sorted.ts +++ b/src/core/classes/delegate-sorted.ts @@ -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(); + } + }); } /** diff --git a/src/core/classes/delegate.ts b/src/core/classes/delegate.ts index f57b133f9..3e5e7aac3 100644 --- a/src/core/classes/delegate.ts +++ b/src/core/classes/delegate.ts @@ -98,6 +98,11 @@ export class CoreDelegate { 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 { const currentSite = CoreSites.getCurrentSite(); let promise: Promise; - 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); diff --git a/src/core/features/login/pages/site-policy/site-policy.ts b/src/core/features/login/pages/site-policy/site-policy.ts index 8c4097f9e..17aba15e3 100644 --- a/src/core/features/login/pages/site-policy/site-policy.ts +++ b/src/core/features/login/pages/site-policy/site-policy.ts @@ -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.'); diff --git a/src/core/singletons/events.ts b/src/core/singletons/events.ts index 49aa650a5..a88ea0722 100644 --- a/src/core/singletons/events.ts +++ b/src/core/singletons/events.ts @@ -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';