Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33308493
D13092.1768801907.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D13092.1768801907.diff
View Options
diff --git a/lib/keyserver-conn/keyserver-connection-handler.js b/lib/keyserver-conn/keyserver-connection-handler.js
--- a/lib/keyserver-conn/keyserver-connection-handler.js
+++ b/lib/keyserver-conn/keyserver-connection-handler.js
@@ -1,5 +1,6 @@
// @flow
+import invariant from 'invariant';
import * as React from 'react';
import { useCallKeyserverEndpointContext } from './call-keyserver-endpoint-provider.react.js';
@@ -7,6 +8,7 @@
import { useRawKeyserverAuth } from './keyserver-auth.js';
import type { CallKeyserverEndpoint } from './keyserver-conn-types.js';
import { useKeyserverRecoveryLogIn } from './recovery-utils.js';
+import { useRecreateNotifsOlmSession } from '../actions/keyserver-actions.js';
import { logOutActionTypes, useLogOut } from '../actions/user-actions.js';
import {
connectionSelector,
@@ -14,6 +16,7 @@
} from '../selectors/keyserver-selectors.js';
import { isLoggedInToKeyserver } from '../selectors/user-selectors.js';
import { useInitialNotificationsEncryptedMessage } from '../shared/crypto-utils.js';
+import { IdentityClientContext } from '../shared/identity-client-context.js';
import type { BaseSocketProps } from '../socket/socket.react.js';
import {
logInActionSources,
@@ -43,6 +46,10 @@
const { olmAPI } = getConfig();
+ const identityContext = React.useContext(IdentityClientContext);
+ invariant(identityContext, 'Identity context should be set');
+ const { identityClient } = identityContext;
+
const hasConnectionIssue = useSelector(
state => !!connectionSelector(keyserverID)(state)?.connectionIssue,
);
@@ -298,6 +305,108 @@
performAuth,
]);
+ const {
+ initializeCryptoAccount,
+ getUserPublicKey,
+ isKeyserverNotificationsSessionInitialized,
+ ephemeralKeyserverNotifsSessionCreator,
+ persistEphemeralKeyserverNotifsSession,
+ } = olmAPI;
+
+ const recreateKeyserverNotifsSessionPromiseRef =
+ React.useRef<?Promise<void>>(null);
+ const recreateNotifsOlmSession = useRecreateNotifsOlmSession();
+
+ const recreateNotifsOlmSessionWithKeyserver = React.useCallback(async () => {
+ if (
+ !ephemeralKeyserverNotifsSessionCreator ||
+ !isKeyserverNotificationsSessionInitialized ||
+ !persistEphemeralKeyserverNotifsSession
+ ) {
+ return;
+ }
+ const hasSessionWithKeyserver =
+ await isKeyserverNotificationsSessionInitialized(keyserverID);
+
+ if (hasSessionWithKeyserver) {
+ return;
+ }
+
+ const identityKeysBlobPromise = (async () => {
+ await initializeCryptoAccount();
+ return await getUserPublicKey();
+ })();
+
+ const [
+ keyserverKeys,
+ { primaryIdentityPublicKeys, notificationIdentityPublicKeys },
+ ] = await Promise.all([
+ identityClient.getKeyserverKeys(keyserverID),
+ identityKeysBlobPromise,
+ ]);
+
+ const { initialEncryptedMessage, sessionPersistenceData } =
+ await ephemeralKeyserverNotifsSessionCreator(
+ cookie,
+ keyserverKeys.identityKeysBlob.notificationIdentityPublicKeys,
+ keyserverKeys.notifInitializationInfo,
+ keyserverID,
+ );
+
+ await recreateNotifsOlmSession({
+ identityKeysBlob: {
+ primaryIdentityPublicKeys,
+ notificationIdentityPublicKeys,
+ },
+ initialEncryptedMessage,
+ keyserverID,
+ });
+
+ await persistEphemeralKeyserverNotifsSession(sessionPersistenceData);
+ }, [
+ cookie,
+ ephemeralKeyserverNotifsSessionCreator,
+ persistEphemeralKeyserverNotifsSession,
+ getUserPublicKey,
+ initializeCryptoAccount,
+ identityClient,
+ keyserverID,
+ isKeyserverNotificationsSessionInitialized,
+ recreateNotifsOlmSession,
+ ]);
+
+ React.useEffect(() => {
+ if (
+ !ephemeralKeyserverNotifsSessionCreator ||
+ !isKeyserverNotificationsSessionInitialized ||
+ !hasCurrentUserInfo ||
+ !hasAccessToken ||
+ !isUserLoggedInToKeyserver ||
+ authInProgress ||
+ !!recreateKeyserverNotifsSessionPromiseRef.current
+ ) {
+ return;
+ }
+
+ recreateKeyserverNotifsSessionPromiseRef.current = (async () => {
+ try {
+ await recreateNotifsOlmSessionWithKeyserver();
+ } catch (e) {
+ console.log(e);
+ } finally {
+ recreateKeyserverNotifsSessionPromiseRef.current = null;
+ }
+ })();
+ }, [
+ recreateNotifsOlmSessionWithKeyserver,
+ isKeyserverNotificationsSessionInitialized,
+ ephemeralKeyserverNotifsSessionCreator,
+ hasCurrentUserInfo,
+ hasAccessToken,
+ isUserLoggedInToKeyserver,
+ authInProgress,
+ ]);
+
return <Socket {...socketProps} />;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 19, 5:51 AM (18 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5954658
Default Alt Text
D13092.1768801907.diff (4 KB)
Attached To
Mode
D13092: Implement keyserver notifs olm session recreation logic in keyserver-connection-handler
Attached
Detach File
Event Timeline
Log In to Comment