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 @@ -21,7 +21,11 @@ import { useKeyserverCall } from '../keyserver-conn/keyserver-call.js'; import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js'; import { usePreRequestUserState } from '../selectors/account-selectors.js'; -import { getForeignPeerDeviceIDs } from '../selectors/user-selectors.js'; +import { + getForeignPeerDeviceIDs, + getOwnPeerDevices, + getKeyserverDeviceID, +} from '../selectors/user-selectors.js'; import { getOneTimeKeyValuesFromBlob, getPrekeyValueFromBlob, @@ -172,6 +176,12 @@ state => state.commServicesAccessToken, ); + const ownPeerDevices = useSelector(getOwnPeerDevices); + const ownedKeyserverDeviceID = React.useMemo( + () => getKeyserverDeviceID(ownPeerDevices), + [ownPeerDevices], + ); + const { logOutType, skipIdentityLogOut, handleUseNewFlowResponse } = options; return React.useCallback( async (keyserverIDs?: $ReadOnlyArray) => { @@ -204,7 +214,12 @@ 'Are you calling it on non-primary device?', ); } - callIdentityClientLogOut = identityClient.logOutPrimaryDevice; + // For Flow - we want above null-check to throw now, + // not inside below async block. + const logOutFunc = identityClient.logOutPrimaryDevice; + callIdentityClientLogOut = async () => { + await logOutFunc(ownedKeyserverDeviceID); + }; } else if (logOutType === 'secondary_device') { callIdentityClientLogOut = identityClient.logOutSecondaryDevice; } else { @@ -266,6 +281,7 @@ commServicesAccessToken, identityClient, logOutType, + ownedKeyserverDeviceID, preRequestUserState, removeAllHolders, skipIdentityLogOut, diff --git a/lib/shared/device-list-utils.js b/lib/shared/device-list-utils.js --- a/lib/shared/device-list-utils.js +++ b/lib/shared/device-list-utils.js @@ -134,8 +134,12 @@ async function createAndSignSingletonDeviceList( primaryDeviceID: string, + keyserverDeviceID?: ?string, ): Promise { - const initialDeviceList = composeRawDeviceList([primaryDeviceID]); + const devices = keyserverDeviceID + ? [primaryDeviceID, keyserverDeviceID] + : [primaryDeviceID]; + const initialDeviceList = composeRawDeviceList(devices); const rawDeviceList = JSON.stringify(initialDeviceList); const { olmAPI } = getConfig(); const curPrimarySignature = await olmAPI.signMessage(rawDeviceList); diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js --- a/lib/types/identity-service-types.js +++ b/lib/types/identity-service-types.js @@ -129,7 +129,7 @@ +logOut: () => Promise; // This log out type is specific to primary device, and web cannot be a // primary device - +logOutPrimaryDevice?: () => Promise; + +logOutPrimaryDevice?: (keyserverDeviceID: ?string) => Promise; +logOutSecondaryDevice: () => Promise; +getKeyserverKeys: string => Promise; // Users cannot register from web diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -157,14 +157,16 @@ commRustModule.logOut(userID, deviceID, token), ); }, - logOutPrimaryDevice: async () => { + logOutPrimaryDevice: async (keyserverDeviceID: ?string) => { const { deviceID, userID, accessToken: token, } = await getAuthMetadata(); - const signedDeviceList = - await createAndSignSingletonDeviceList(deviceID); + const signedDeviceList = await createAndSignSingletonDeviceList( + deviceID, + keyserverDeviceID, + ); return authVerifiedEndpoint( commRustModule.logOutPrimaryDevice( userID,