Changeset View
Changeset View
Standalone View
Standalone View
lib/components/keyserver-connection-handler.js
Show All 18 Lines | |||||
import { | import { | ||||
connectionSelector, | connectionSelector, | ||||
cookieSelector, | cookieSelector, | ||||
deviceTokenSelector, | deviceTokenSelector, | ||||
} from '../selectors/keyserver-selectors.js'; | } from '../selectors/keyserver-selectors.js'; | ||||
import { isLoggedInToKeyserver } from '../selectors/user-selectors.js'; | import { isLoggedInToKeyserver } from '../selectors/user-selectors.js'; | ||||
import { useInitialNotificationsEncryptedMessage } from '../shared/crypto-utils.js'; | import { useInitialNotificationsEncryptedMessage } from '../shared/crypto-utils.js'; | ||||
import { IdentityClientContext } from '../shared/identity-client-context.js'; | import { IdentityClientContext } from '../shared/identity-client-context.js'; | ||||
import { OlmSessionCreatorContext } from '../shared/olm-session-creator-context.js'; | |||||
import type { BaseSocketProps } from '../socket/socket.react.js'; | import type { BaseSocketProps } from '../socket/socket.react.js'; | ||||
import { | import { | ||||
logInActionSources, | logInActionSources, | ||||
type RecoveryActionSource, | type RecoveryActionSource, | ||||
} from '../types/account-types.js'; | } from '../types/account-types.js'; | ||||
import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; | import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; | ||||
import type { CallSingleKeyserverEndpoint } from '../utils/call-single-keyserver-endpoint.js'; | import type { CallSingleKeyserverEndpoint } from '../utils/call-single-keyserver-endpoint.js'; | ||||
import { getConfig } from '../utils/config.js'; | import { getConfig } from '../utils/config.js'; | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | ) { | ||||
void dispatchActionPromise(logOutActionTypes, callLogOut()); | void dispatchActionPromise(logOutActionTypes, callLogOut()); | ||||
} | } | ||||
}, [callLogOut, hasConnectionIssue, dispatchActionPromise, keyserverID]); | }, [callLogOut, hasConnectionIssue, dispatchActionPromise, keyserverID]); | ||||
const identityContext = React.useContext(IdentityClientContext); | const identityContext = React.useContext(IdentityClientContext); | ||||
invariant(identityContext, 'Identity context should be set'); | invariant(identityContext, 'Identity context should be set'); | ||||
const { identityClient, getAuthMetadata } = identityContext; | const { identityClient, getAuthMetadata } = identityContext; | ||||
const olmSessionCreator = React.useContext(OlmSessionCreatorContext); | const { olmAPI } = getConfig(); | ||||
invariant(olmSessionCreator, 'Olm session creator should be set'); | |||||
const [authInProgress, setAuthInProgress] = React.useState(false); | const [authInProgress, setAuthInProgress] = React.useState(false); | ||||
const performAuth = React.useCallback(() => { | const performAuth = React.useCallback(() => { | ||||
setAuthInProgress(true); | setAuthInProgress(true); | ||||
let cancelled = false; | let cancelled = false; | ||||
const cancel = () => { | const cancel = () => { | ||||
cancelled = true; | cancelled = true; | ||||
setAuthInProgress(false); | setAuthInProgress(false); | ||||
}; | }; | ||||
const promise = (async () => { | const promise = (async () => { | ||||
try { | try { | ||||
const keyserverKeys = | const [keyserverKeys] = await Promise.all([ | ||||
await identityClient.getKeyserverKeys(keyserverID); | identityClient.getKeyserverKeys(keyserverID), | ||||
olmAPI.initializeCryptoAccount(), | |||||
]); | |||||
if (cancelled) { | if (cancelled) { | ||||
throw new Error(CANCELLED_ERROR); | throw new Error(CANCELLED_ERROR); | ||||
} | } | ||||
const [notifsSession, contentSession, { userID, deviceID }] = | const [notifsSession, contentSession, { userID, deviceID }] = | ||||
await Promise.all([ | await Promise.all([ | ||||
olmSessionCreator.notificationsSessionCreator( | olmAPI.notificationsSessionCreator( | ||||
cookie, | cookie, | ||||
keyserverKeys.identityKeysBlob.notificationIdentityPublicKeys, | keyserverKeys.identityKeysBlob.notificationIdentityPublicKeys, | ||||
keyserverKeys.notifInitializationInfo, | keyserverKeys.notifInitializationInfo, | ||||
keyserverID, | keyserverID, | ||||
), | ), | ||||
olmSessionCreator.contentSessionCreator( | olmAPI.contentOutboundSessionCreator( | ||||
keyserverKeys.identityKeysBlob.primaryIdentityPublicKeys, | keyserverKeys.identityKeysBlob.primaryIdentityPublicKeys, | ||||
keyserverKeys.contentInitializationInfo, | keyserverKeys.contentInitializationInfo, | ||||
), | ), | ||||
getAuthMetadata(), | getAuthMetadata(), | ||||
]); | ]); | ||||
invariant(userID, 'userID should be set'); | invariant(userID, 'userID should be set'); | ||||
invariant(deviceID, 'deviceID should be set'); | invariant(deviceID, 'deviceID should be set'); | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | const performAuth = React.useCallback(() => { | ||||
cookie, | cookie, | ||||
dataLoaded, | dataLoaded, | ||||
deviceToken, | deviceToken, | ||||
dispatchActionPromise, | dispatchActionPromise, | ||||
getAuthMetadata, | getAuthMetadata, | ||||
identityClient, | identityClient, | ||||
keyserverAuth, | keyserverAuth, | ||||
keyserverID, | keyserverID, | ||||
olmSessionCreator, | olmAPI, | ||||
]); | ]); | ||||
const activeSessionRecovery = useSelector( | const activeSessionRecovery = useSelector( | ||||
state => | state => | ||||
state.keyserverStore.keyserverInfos[keyserverID]?.connection | state.keyserverStore.keyserverInfos[keyserverID]?.connection | ||||
.activeSessionRecovery, | .activeSessionRecovery, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |