diff --git a/keyserver/src/fetchers/policy-acknowledgment-fetchers.js b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js --- a/keyserver/src/fetchers/policy-acknowledgment-fetchers.js +++ b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js @@ -36,4 +36,19 @@ }); } -export { fetchPolicyAcknowledgments, fetchNotAcknowledgedPolicies }; +async function hasAnyNotAcknowledgedPolicies( + viewer: Viewer, + policies: $ReadOnlyArray, +): Promise { + const notAcknowledgedPolicies = await fetchNotAcknowledgedPolicies( + viewer, + policies, + ); + return !!notAcknowledgedPolicies.length; +} + +export { + fetchPolicyAcknowledgments, + fetchNotAcknowledgedPolicies, + hasAnyNotAcknowledgedPolicies, +}; diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js --- a/keyserver/src/responders/website-responders.js +++ b/keyserver/src/responders/website-responders.js @@ -8,6 +8,7 @@ import ReactDOMServer from 'react-dom/server'; import { promisify } from 'util'; +import { baseLegalPolicies } from 'lib/facts/policies.js'; import { daysToEntriesFromEntryInfos } from 'lib/reducers/entry-reducer'; import { freshMessageStore } from 'lib/reducers/message-reducer'; import { mostRecentlyReadThread } from 'lib/selectors/thread-selectors'; @@ -32,6 +33,7 @@ import { fetchEntryInfos } from '../fetchers/entry-fetchers'; import { fetchMessageInfos } from '../fetchers/message-fetchers'; +import { hasAnyNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js'; import { fetchThreadInfos } from '../fetchers/thread-fetchers'; import { fetchCurrentUserInfo, @@ -126,6 +128,10 @@ const baseHref = baseDomain + baseURL; const loadingPromise = getWebpackCompiledRootComponentForSSR(); + const hasNotAcknowledgedPoliciesPromise = hasAnyNotAcknowledgedPolicies( + viewer, + baseLegalPolicies, + ); let initialNavInfo; try { @@ -163,10 +169,23 @@ })(); const threadStorePromise = (async () => { + const hasNotAcknowledgedPolicies = await hasNotAcknowledgedPoliciesPromise; + if (hasNotAcknowledgedPolicies) { + return { threadInfos: {} }; + } const { threadInfos } = await threadInfoPromise; return { threadInfos }; })(); const messageStorePromise = (async () => { + const hasNotAcknowledgedPolicies = await hasNotAcknowledgedPoliciesPromise; + if (hasNotAcknowledgedPolicies) { + return { + messages: {}, + threads: {}, + local: {}, + currentAsOf: 0, + }; + } const [ { threadInfos }, { rawMessageInfos, truncationStatuses }, @@ -180,6 +199,14 @@ return freshStore; })(); const entryStorePromise = (async () => { + const hasNotAcknowledgedPolicies = await hasNotAcknowledgedPoliciesPromise; + if (hasNotAcknowledgedPolicies) { + return { + entryInfos: {}, + daysToEntries: {}, + lastUserInteractionCalendar: 0, + }; + } const { rawEntryInfos } = await entryInfoPromise; return { entryInfos: _keyBy('id')(rawEntryInfos), @@ -188,6 +215,13 @@ }; })(); const userStorePromise = (async () => { + const hasNotAcknowledgedPolicies = await hasNotAcknowledgedPoliciesPromise; + if (hasNotAcknowledgedPolicies) { + return { + userInfos: {}, + inconsistencyReports: [], + }; + } const userInfos = await userInfoPromise; return { userInfos, inconsistencyReports: [] }; })(); @@ -308,6 +342,8 @@ var preloadedState = `); + const hasNotAcknowledgedPolicies = await hasNotAcknowledgedPoliciesPromise; + const initialReduxState = await promiseAll({ navInfo: navInfoPromise, deviceID: null, @@ -318,7 +354,7 @@ threadStore: threadStorePromise, userStore: userStorePromise, messageStore: messageStorePromise, - updatesCurrentAsOf: initialTime, + updatesCurrentAsOf: hasNotAcknowledgedPolicies ? 0 : initialTime, loadingStatuses: {}, calendarFilters: defaultCalendarFilters, // We can use paths local to the on web