diff --git a/lib/components/peer-olm-session-creator-provider.react.js b/lib/components/peer-olm-session-creator-provider.react.js --- a/lib/components/peer-olm-session-creator-provider.react.js +++ b/lib/components/peer-olm-session-creator-provider.react.js @@ -5,12 +5,16 @@ import { IdentityClientContext } from '../shared/identity-client-context.js'; import { useTunnelbroker } from '../tunnelbroker/tunnelbroker-context.js'; -import { createOlmSessionWithPeer } from '../utils/crypto-utils.js'; +import { + createOlmSessionWithPeer, + type SessionCreationOptions, +} from '../utils/crypto-utils.js'; export type PeerOlmSessionCreatorContextType = { +createOlmSessionsWithPeer: ( userID: string, deviceID: string, + sessionCreationOptions?: SessionCreationOptions, ) => Promise, }; @@ -32,7 +36,11 @@ }>({}); const createOlmSessionsWithPeer = React.useCallback( - (userID: string, deviceID: string) => { + ( + userID: string, + deviceID: string, + sessionCreationOptions?: SessionCreationOptions, + ) => { if ( runningPromises.current[userID] && runningPromises.current[userID][deviceID] @@ -48,6 +56,7 @@ sendMessageToDevice, userID, deviceID, + sessionCreationOptions, ); runningPromises.current[userID][deviceID] = null; diff --git a/lib/utils/crypto-utils.js b/lib/utils/crypto-utils.js --- a/lib/utils/crypto-utils.js +++ b/lib/utils/crypto-utils.js @@ -107,18 +107,33 @@ } } +export type SessionCreationOptions = { + +overwriteNotifSession?: boolean, + +overwriteontentSession?: boolean, +}; async function createOlmSessionWithPeer( authMetadata: AuthMetadata, identityClient: IdentityServiceClient, sendMessage: (message: TunnelbrokerClientMessageToDevice) => Promise, userID: string, deviceID: string, + options?: SessionCreationOptions, ): Promise { const { olmAPI } = getConfig(); await olmAPI.initializeCryptoAccount(); const [hasContentSession, hasNotifsSession] = await Promise.all([ - olmAPI.isContentSessionInitialized(deviceID), - olmAPI.isDeviceNotificationsSessionInitialized(deviceID), + (async () => { + if (options?.overwriteontentSession) { + return false; + } + return await olmAPI.isContentSessionInitialized(deviceID); + })(), + (async () => { + if (options?.overwriteNotifSession) { + return false; + } + return await olmAPI.isDeviceNotificationsSessionInitialized(deviceID); + })(), ]); if (hasContentSession && hasNotifsSession) {