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 @@ -79,6 +79,7 @@ createAccount, processSIWEAccountCreation, } from '../creators/account-creator.js'; +import { createOlmSession } from '../creators/olm-session-creator.js'; import { dbQuery, SQL } from '../database/database.js'; import { deleteAccount } from '../deleters/account-deleters.js'; import { deleteCookie } from '../deleters/cookie-deleters.js'; @@ -253,6 +254,7 @@ +calendarQuery: ?CalendarQuery, +socialProof?: ?SIWESocialProof, +signedIdentityKeysBlob?: ?SignedIdentityKeysBlob, + +initialNotificationsEncryptedMessage?: string, }; async function processSuccessfulLogin( @@ -265,6 +267,7 @@ calendarQuery, socialProof, signedIdentityKeysBlob, + initialNotificationsEncryptedMessage, } = params; const request: LogInRequest = input; @@ -307,6 +310,19 @@ if (calendarQuery) { await setNewSession(viewer, calendarQuery, newServerTime); } + const olmSessionPromise = (async () => { + if ( + userViewerData.cookieID && + initialNotificationsEncryptedMessage && + signedIdentityKeysBlob + ) { + await createOlmSession( + initialNotificationsEncryptedMessage, + 'notifications', + userViewerData.cookieID, + ); + } + })(); const threadCursors = {}; for (const watchedThreadID of request.watchedIDs) { @@ -326,6 +342,7 @@ calendarQuery ? fetchEntryInfos(viewer, [calendarQuery]) : undefined, fetchKnownUserInfos(viewer), fetchLoggedInUserInfo(viewer), + olmSessionPromise, ]); const rawEntryInfos = entriesResult ? entriesResult.rawEntryInfos : null; @@ -362,6 +379,7 @@ // old clients, but we no longer do anything with it. primaryIdentityPublicKey: t.maybe(tRegex(primaryIdentityPublicKeyRegex)), signedIdentityKeysBlob: t.maybe(signedIdentityKeysBlobValidator), + initialNotificationsEncryptedMessage: t.maybe(t.String), }); async function logInResponder( @@ -372,7 +390,8 @@ const request: LogInRequest = input; let identityKeys: ?IdentityKeysBlob; - const { signedIdentityKeysBlob } = request; + const { signedIdentityKeysBlob, initialNotificationsEncryptedMessage } = + request; if (signedIdentityKeysBlob) { identityKeys = JSON.parse(signedIdentityKeysBlob.payload); @@ -436,6 +455,7 @@ userID: id, calendarQuery, signedIdentityKeysBlob, + initialNotificationsEncryptedMessage, }); } 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 @@ -104,6 +104,7 @@ +calendarQuery: CalendarQuery, +deviceTokenUpdateRequest?: ?DeviceTokenUpdateRequest, +signedIdentityKeysBlob?: SignedIdentityKeysBlob, + +initialNotificationsEncryptedMessage?: string, }; export type LogInInfo = { @@ -123,6 +124,7 @@ +watchedIDs: $ReadOnlyArray, +source?: LogInActionSource, +signedIdentityKeysBlob?: SignedIdentityKeysBlob, + +initialNotificationsEncryptedMessage?: string, }; export type LogInResponse = { diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js --- a/native/account/log-in-panel.react.js +++ b/native/account/log-in-panel.react.js @@ -37,6 +37,7 @@ import { useSelector } from '../redux/redux-utils.js'; import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; import type { KeyPressEvent } from '../types/react-native.js'; +import { useInitialNotificationsEncryptedMessage } from '../utils/crypto-utils.js'; import type { StateContainer } from '../utils/state-container.js'; export type LogInState = { @@ -54,6 +55,7 @@ +logInExtraInfo: () => Promise, +dispatchActionPromise: DispatchActionPromise, +logIn: (logInInfo: LogInInfo) => Promise, + +initialNotificationsEncryptedMessage: () => Promise, }; class LogInPanel extends React.PureComponent { usernameInput: ?TextInput; @@ -227,9 +229,12 @@ Keyboard.dismiss(); const extraInfo = await this.props.logInExtraInfo(); + const initialNotificationsEncryptedMessage = + await this.props.initialNotificationsEncryptedMessage(); + console.log(initialNotificationsEncryptedMessage); this.props.dispatchActionPromise( logInActionTypes, - this.logInAction(extraInfo), + this.logInAction({ ...extraInfo, initialNotificationsEncryptedMessage }), undefined, ({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload), ); @@ -364,6 +369,8 @@ const dispatchActionPromise = useDispatchActionPromise(); const callLogIn = useServerCall(logIn); + const callInitialNotificationsEncryptedMessage = + useInitialNotificationsEncryptedMessage(); return ( ); });