Page MenuHomePhabricator

D13372.id44290.diff
No OneTemporary

D13372.id44290.diff

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
@@ -16,10 +16,9 @@
};
export type PeerOlmSessionCreatorContextType = {
- +createOlmSessionsWithPeer: (
+ +createOlmSessionsWithUser: (
userID: string,
- deviceID: string,
- sessionCreationOptions?: SessionCreationOptions,
+ devices: $ReadOnlyArray<DeviceSessionCreationRequest>,
) => Promise<void>,
};
@@ -37,20 +36,13 @@
const { sendMessageToDevice } = useTunnelbroker();
const runningPromises = React.useRef<{
- [userID: string]: { [deviceID: string]: ?Promise<void> },
+ [userID: string]: ?Promise<void>,
}>({});
- const createOlmSessionsWithPeer = React.useCallback(
- (
- userID: string,
- deviceID: string,
- sessionCreationOptions?: SessionCreationOptions,
- ) => {
- if (
- runningPromises.current[userID] &&
- runningPromises.current[userID][deviceID]
- ) {
- return runningPromises.current[userID][deviceID];
+ const createOlmSessionsWithUserCallback = React.useCallback(
+ (userID: string, devices: $ReadOnlyArray<DeviceSessionCreationRequest>) => {
+ if (runningPromises.current[userID]) {
+ return runningPromises.current[userID];
}
const promise = (async () => {
@@ -60,17 +52,13 @@
identityClient,
sendMessageToDevice,
userID,
- [{ deviceID, sessionCreationOptions }],
+ devices,
);
- runningPromises.current[userID][deviceID] = null;
+ runningPromises.current[userID] = null;
})();
- if (!runningPromises.current[userID]) {
- runningPromises.current[userID] = {};
- }
-
- runningPromises.current[userID][deviceID] = promise;
+ runningPromises.current[userID] = promise;
return promise;
},
[identityClient, sendMessageToDevice, getAuthMetadata],
@@ -78,8 +66,10 @@
const peerOlmSessionCreatorContextValue: PeerOlmSessionCreatorContextType =
React.useMemo(
- () => ({ createOlmSessionsWithPeer }),
- [createOlmSessionsWithPeer],
+ () => ({
+ createOlmSessionsWithUser: createOlmSessionsWithUserCallback,
+ }),
+ [createOlmSessionsWithUserCallback],
);
return (
diff --git a/lib/push/send-hooks.react.js b/lib/push/send-hooks.react.js
--- a/lib/push/send-hooks.react.js
+++ b/lib/push/send-hooks.react.js
@@ -109,7 +109,7 @@
const userInfos = useSelector(state => state.userStore.userInfos);
const { getENSNames } = React.useContext(ENSCacheContext);
const getFCNames = React.useContext(NeynarClientContext)?.getFCNames;
- const { createOlmSessionsWithPeer: olmSessionCreator } =
+ const { createOlmSessionsWithUser: olmSessionCreator } =
usePeerOlmSessionsCreatorContext();
const { sendNotif } = useTunnelbroker();
const { encryptedNotifUtilsAPI } = getConfig();
diff --git a/lib/push/send-utils.js b/lib/push/send-utils.js
--- a/lib/push/send-utils.js
+++ b/lib/push/send-utils.js
@@ -21,6 +21,7 @@
} from './utils.js';
import { createWebNotification } from './web-notif-creators.js';
import { createWNSNotification } from './wns-notif-creators.js';
+import type { DeviceSessionCreationRequest } from '../components/peer-olm-session-creator-provider.react.js';
import { hasPermission } from '../permissions/minimally-encoded-thread-permissions.js';
import {
rawMessageInfoFromMessageData,
@@ -965,7 +966,10 @@
deviceIDsToUserIDs: {
+[string]: string,
},
- olmSessionCreator: (userID: string, deviceID: string) => Promise<void>,
+ olmSessionCreator: (
+ userID: string,
+ devices: $ReadOnlyArray<DeviceSessionCreationRequest>,
+ ) => Promise<void>,
): Promise<void> {
const {
initializeCryptoAccount,
@@ -984,7 +988,7 @@
continue;
}
olmSessionCreationPromises.push(
- olmSessionCreator(deviceIDsToUserIDs[deviceID], deviceID),
+ olmSessionCreator(deviceIDsToUserIDs[deviceID], [{ deviceID }]),
);
}
@@ -1033,7 +1037,10 @@
type PreparePushNotifsInputData = {
+encryptedNotifUtilsAPI: EncryptedNotifUtilsAPI,
+senderDeviceDescriptor: SenderDeviceDescriptor,
- +olmSessionCreator: (userID: string, deviceID: string) => Promise<void>,
+ +olmSessionCreator: (
+ userID: string,
+ devices: $ReadOnlyArray<DeviceSessionCreationRequest>,
+ ) => Promise<void>,
+messageInfos: { +[id: string]: RawMessageInfo },
+thickRawThreadInfos: ThickRawThreadInfos,
+auxUserInfos: AuxUserInfos,
@@ -1095,7 +1102,10 @@
type PrepareOwnDevicesPushNotifsInputData = {
+encryptedNotifUtilsAPI: EncryptedNotifUtilsAPI,
+senderInfo: SenderInfo,
- +olmSessionCreator: (userID: string, deviceID: string) => Promise<void>,
+ +olmSessionCreator: (
+ userID: string,
+ devices: $ReadOnlyArray<DeviceSessionCreationRequest>,
+ ) => Promise<void>,
+auxUserInfos: AuxUserInfos,
+rescindData?: { threadID: string },
+badgeUpdateData?: { threadID: string },
diff --git a/lib/tunnelbroker/peer-to-peer-context.js b/lib/tunnelbroker/peer-to-peer-context.js
--- a/lib/tunnelbroker/peer-to-peer-context.js
+++ b/lib/tunnelbroker/peer-to-peer-context.js
@@ -8,7 +8,10 @@
type TunnelbrokerClientMessageToDevice,
useTunnelbroker,
} from './tunnelbroker-context.js';
-import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js';
+import {
+ usePeerOlmSessionsCreatorContext,
+ type DeviceSessionCreationRequest,
+} from '../components/peer-olm-session-creator-provider.react.js';
import { useSendPushNotifs } from '../push/send-hooks.react.js';
import {
type AuthMetadata,
@@ -66,7 +69,10 @@
messageID: ?string,
) => Promise<void>,
identityContext: IdentityClientContextType,
- peerOlmSessionsCreator: (userID: string, deviceID: string) => Promise<void>,
+ peerOlmSessionsCreator: (
+ userID: string,
+ devices: $ReadOnlyArray<DeviceSessionCreationRequest>,
+ ) => Promise<void>,
messageIDs: ?$ReadOnlyArray<string>,
): Promise<ProcessOutboundP2PMessagesResult> {
let authMetadata;
@@ -175,7 +181,9 @@
break;
}
try {
- await peerOlmSessionsCreator(message.userID, peerDeviceID);
+ await peerOlmSessionsCreator(message.userID, [
+ { deviceID: peerDeviceID },
+ ]);
const result = await olmAPI.encryptAndPersist(
message.plaintext,
message.deviceID,
@@ -264,7 +272,7 @@
>([]);
const promiseRunning = React.useRef<boolean>(false);
- const { createOlmSessionsWithPeer: peerOlmSessionsCreator } =
+ const { createOlmSessionsWithUser: peerOlmSessionsCreator } =
usePeerOlmSessionsCreatorContext();
const sendPushNotifs = useSendPushNotifs();
@@ -371,7 +379,9 @@
return;
}
try {
- await peerOlmSessionsCreator(recipient.userID, recipient.deviceID);
+ await peerOlmSessionsCreator(recipient.userID, [
+ { deviceID: recipient.deviceID },
+ ]);
const encryptedData = await olmAPI.encrypt(
contentPayload,
recipient.deviceID,
diff --git a/lib/tunnelbroker/use-peer-to-peer-message-handler.js b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
--- a/lib/tunnelbroker/use-peer-to-peer-message-handler.js
+++ b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
@@ -192,7 +192,7 @@
const handleOlmMessageToDevice = useHandleOlmMessageToDevice();
const resendPeerToPeerMessages = useResendPeerToPeerMessages();
- const { createOlmSessionsWithPeer } = usePeerOlmSessionsCreatorContext();
+ const { createOlmSessionsWithUser } = usePeerOlmSessionsCreatorContext();
return React.useCallback(
async (message: PeerToPeerMessage, messageID: string) => {
@@ -311,13 +311,12 @@
throw e;
}
- await createOlmSessionsWithPeer(
- message.senderInfo.userID,
- message.senderInfo.deviceID,
+ await createOlmSessionsWithUser(message.senderInfo.userID, [
{
- overwriteContentSession: true,
+ deviceID: message.senderInfo.deviceID,
+ sessionCreationOptions: { overwriteContentSession: true },
},
- );
+ ]);
await resendPeerToPeerMessages(message.senderInfo.deviceID);
}
} else if (message.type === peerToPeerMessageTypes.REFRESH_KEY_REQUEST) {
@@ -410,7 +409,7 @@
},
[
broadcastDeviceListUpdates,
- createOlmSessionsWithPeer,
+ createOlmSessionsWithUser,
dispatch,
foreignPeerDevices,
getAndUpdateDeviceListsForUsers,

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 20, 3:20 AM (19 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2328818
Default Alt Text
D13372.id44290.diff (8 KB)

Event Timeline