diff --git a/keyserver/src/endpoints.js b/keyserver/src/endpoints.js --- a/keyserver/src/endpoints.js +++ b/keyserver/src/endpoints.js @@ -1,6 +1,6 @@ // @flow -import { policyTypes } from 'lib/facts/policies.js'; +import { baseLegalPolicies } from 'lib/facts/policies.js'; import type { Endpoint } from 'lib/types/endpoints'; import { @@ -60,8 +60,6 @@ import { codeVerificationResponder } from './responders/verification-responders'; import { uploadDeletionResponder } from './uploads/uploads'; -const baseLegalPolicies = [policyTypes.tosAndPrivacyPolicy]; - const jsonEndpoints: { [id: Endpoint]: JSONResponder } = { create_account: { responder: accountCreationResponder, diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -5,7 +5,7 @@ import t from 'tcomb'; import bcrypt from 'twin-bcrypt'; -import { policies } from 'lib/facts/policies.js'; +import { baseLegalPolicies, policies } from 'lib/facts/policies.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils'; import type { ResetPasswordRequest, @@ -62,6 +62,7 @@ import { checkAndInvalidateSIWENonceEntry } from '../deleters/siwe-nonce-deleters.js'; import { fetchEntryInfos } from '../fetchers/entry-fetchers'; import { fetchMessageInfos } from '../fetchers/message-fetchers'; +import { fetchNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js'; import { fetchThreadInfos } from '../fetchers/thread-fetchers'; import { fetchKnownUserInfos, @@ -215,16 +216,38 @@ const deviceToken = request.deviceTokenUpdateRequest ? request.deviceTokenUpdateRequest.deviceToken : viewer.deviceToken; - const [userViewerData] = await Promise.all([ + const [userViewerData, notAcknowledgedPolicies] = await Promise.all([ createNewUserCookie(userID, { platformDetails: request.platformDetails, deviceToken, primaryIdentityPublicKey, socialProof, }), + fetchNotAcknowledgedPolicies(viewer, baseLegalPolicies), deleteCookie(viewer.cookieID), ]); viewer.setNewCookie(userViewerData); + + if ( + notAcknowledgedPolicies.length && + hasMinCodeVersion(viewer.platformDetails, 1000) + ) { + const currentUserInfo = await fetchLoggedInUserInfo(viewer); + return { + notAcknowledgedPolicies, + currentUserInfo: currentUserInfo, + rawMessageInfos: [], + truncationStatuses: {}, + userInfos: [], + rawEntryInfos: [], + serverTime: 0, + cookieChange: { + threadInfos: {}, + userInfos: [], + }, + }; + } + if (calendarQuery) { await setNewSession(viewer, calendarQuery, newServerTime); } @@ -249,8 +272,8 @@ fetchLoggedInUserInfo(viewer), ]); - const rawEntryInfos = entriesResult ? entriesResult.rawEntryInfos : null; - const response: LogInResponse = { + const rawEntryInfos = entriesResult ? entriesResult.rawEntryInfos : undefined; + return { currentUserInfo, rawMessageInfos: messagesResult.rawMessageInfos, truncationStatuses: messagesResult.truncationStatuses, @@ -260,11 +283,8 @@ threadInfos: threadsResult.threadInfos, userInfos: [], }, + rawEntryInfos, }; - if (rawEntryInfos) { - response.rawEntryInfos = rawEntryInfos; - } - return response; } const logInRequestInputValidator = tShape({ diff --git a/lib/actions/siwe-actions.js b/lib/actions/siwe-actions.js --- a/lib/actions/siwe-actions.js +++ b/lib/actions/siwe-actions.js @@ -63,6 +63,7 @@ userInfos, updatesCurrentAsOf: response.serverTime, logInActionSource: logInActionSources.logInFromNativeSIWE, + notAcknowledgedPolicies: response.notAcknowledgedPolicies, }; }; diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -147,6 +147,7 @@ userInfos, updatesCurrentAsOf: response.serverTime, logInActionSource: logInInfo.logInActionSource, + notAcknowledgedPolicies: response.notAcknowledgedPolicies, }; }; diff --git a/lib/facts/policies.js b/lib/facts/policies.js --- a/lib/facts/policies.js +++ b/lib/facts/policies.js @@ -9,3 +9,5 @@ export const policies: $ReadOnlyArray = values(policyTypes); export type PolicyType = $Values; + +export const baseLegalPolicies = [policyTypes.tosAndPrivacyPolicy]; diff --git a/lib/reducers/policies-reducer.js b/lib/reducers/policies-reducer.js --- a/lib/reducers/policies-reducer.js +++ b/lib/reducers/policies-reducer.js @@ -1,6 +1,10 @@ // @flow -import { policyAcknowledgmentActionTypes } from '../actions/user-actions.js'; +import { siweAuthActionTypes } from '../actions/siwe-actions.js'; +import { + logInActionTypes, + policyAcknowledgmentActionTypes, +} from '../actions/user-actions.js'; import type { PolicyType } from '../facts/policies.js'; import { type UserPolicies, @@ -12,8 +16,15 @@ state: UserPolicies, action: BaseAction, ): UserPolicies { - if (action.type === forcePolicyAcknowledgmentActionType) { + if ( + action.type === forcePolicyAcknowledgmentActionType || + action.type === logInActionTypes.success || + action.type === siweAuthActionTypes.success + ) { const { notAcknowledgedPolicies } = action.payload; + if (!notAcknowledgedPolicies) { + return state; + } const newState = { ...state }; notAcknowledgedPolicies.forEach((policy: PolicyType) => { diff --git a/lib/types/account-types.js b/lib/types/account-types.js --- a/lib/types/account-types.js +++ b/lib/types/account-types.js @@ -120,16 +120,17 @@ }; export type LogInResponse = { - currentUserInfo: LoggedInUserInfo | OldLoggedInUserInfo, - rawMessageInfos: $ReadOnlyArray, - truncationStatuses: MessageTruncationStatuses, - userInfos: $ReadOnlyArray, - rawEntryInfos?: ?$ReadOnlyArray, - serverTime: number, - cookieChange: { - threadInfos: { +[id: string]: RawThreadInfo }, - userInfos: $ReadOnlyArray, + +currentUserInfo: LoggedInUserInfo | OldLoggedInUserInfo, + +rawMessageInfos: $ReadOnlyArray, + +truncationStatuses: MessageTruncationStatuses, + +userInfos: $ReadOnlyArray, + +rawEntryInfos?: ?$ReadOnlyArray, + +serverTime: number, + +cookieChange: { + +threadInfos: { +[id: string]: RawThreadInfo }, + +userInfos: $ReadOnlyArray, }, + +notAcknowledgedPolicies?: $ReadOnlyArray, }; export type LogInResult = { @@ -140,6 +141,7 @@ +calendarResult: CalendarResult, +updatesCurrentAsOf: number, +logInActionSource: LogInActionSource, + +notAcknowledgedPolicies?: $ReadOnlyArray, }; export type UpdatePasswordRequest = {