Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3345474
D13373.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D13373.diff
View Options
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
@@ -65,6 +65,7 @@
import type { DeviceSessionCreationRequest } from '../utils/crypto-utils.js';
import { type GetENSNames } from '../utils/ens-helpers.js';
import { type GetFCNames } from '../utils/farcaster-helpers.js';
+import { values } from '../utils/objects.js';
import { promiseAll } from '../utils/promises.js';
export type Device = {
@@ -963,8 +964,8 @@
}
async function createOlmSessionWithDevices(
- deviceIDsToUserIDs: {
- +[string]: string,
+ userDevices: {
+ +[userID: string]: $ReadOnlyArray<string>,
},
olmSessionCreator: (
userID: string,
@@ -979,17 +980,18 @@
const deviceIDsToSessionPresence =
await isNotificationsSessionInitializedWithDevices(
- Object.keys(deviceIDsToUserIDs),
+ values(userDevices).flat(),
);
const olmSessionCreationPromises = [];
- for (const deviceID in deviceIDsToSessionPresence) {
- if (deviceIDsToSessionPresence[deviceID]) {
- continue;
- }
- olmSessionCreationPromises.push(
- olmSessionCreator(deviceIDsToUserIDs[deviceID], [{ deviceID }]),
- );
+ for (const userID in userDevices) {
+ const devices = userDevices[userID]
+ .filter(deviceID => !deviceIDsToSessionPresence[deviceID])
+ .map(deviceID => ({
+ deviceID,
+ }));
+
+ olmSessionCreationPromises.push(olmSessionCreator(userID, devices));
}
try {
@@ -1079,14 +1081,16 @@
const filteredPushInfos = filterDevicesSupportingDMNotifsForUsers(pushInfos);
- const deviceIDsToUserIDs: { [string]: string } = {};
+ const userDevices: {
+ [userID: string]: $ReadOnlyArray<string>,
+ } = {};
for (const userID in filteredPushInfos) {
- for (const device of filteredPushInfos[userID].devices) {
- deviceIDsToUserIDs[device.cryptoID] = userID;
- }
+ userDevices[userID] = filteredPushInfos[userID].devices.map(
+ device => device.cryptoID,
+ );
}
- await createOlmSessionWithDevices(deviceIDsToUserIDs, olmSessionCreator);
+ await createOlmSessionWithDevices(userDevices, olmSessionCreator);
return await buildNotifsFromPushInfo({
encryptedNotifUtilsAPI,
@@ -1133,13 +1137,16 @@
filterDevicesSupportingDMNotifs(ownDevicesPushInfo);
const { senderUserID, senderDeviceDescriptor } = senderInfo;
- const deviceIDsToUserIDs: { [string]: string } = {};
- for (const device of filteredownDevicesPushInfos.devices) {
- deviceIDsToUserIDs[device.cryptoID] = senderUserID;
- }
+ const userDevices: {
+ +[userID: string]: $ReadOnlyArray<string>,
+ } = {
+ [senderUserID]: filteredownDevicesPushInfos.devices.map(
+ device => device.cryptoID,
+ ),
+ };
- await createOlmSessionWithDevices(deviceIDsToUserIDs, olmSessionCreator);
+ await createOlmSessionWithDevices(userDevices, olmSessionCreator);
const devicesByPlatform = getDevicesByPlatform(
filteredownDevicesPushInfos.devices,
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 6:13 AM (18 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569359
Default Alt Text
D13373.diff (2 KB)
Attached To
Mode
D13373: [lib] refactor notif code to support creating session with multiple devices of one user
Attached
Detach File
Event Timeline
Log In to Comment