Skip to content

Commit

Permalink
One check for minimum code version supporting e2ee notifs
Browse files Browse the repository at this point in the history
Summary: This differential ensures that e2ee notifs are sent to devices supporting code version that will be determined during staff e2ee dm's release

Test Plan: Ensure that e2ee notifs work if and only if FUTURE_CODE_VERSION is 0

Reviewers: tomek

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13261
  • Loading branch information
marcinwasowicz committed Sep 12, 2024
1 parent 0773972 commit 29f2689
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
17 changes: 1 addition & 16 deletions lib/push/android-notif-creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
prepareEncryptedAndroidVisualNotifications,
prepareEncryptedAndroidSilentNotifications,
} from './crypto.js';
import {
hasMinCodeVersion,
FUTURE_CODE_VERSION,
} from '../shared/version-utils.js';
import { hasMinCodeVersion } from '../shared/version-utils.js';
import type { PlatformDetails } from '../types/device-types.js';
import { messageTypes } from '../types/message-types-enum.js';
import {
Expand Down Expand Up @@ -288,12 +285,6 @@ async function createAndroidNotificationRescind(
},
};

invariant(
(rescindID && badge) ||
hasMinCodeVersion(platformDetails, { native: FUTURE_CODE_VERSION }),
'thick thread rescind not support for this client version',
);

if (rescindID && badge) {
notification = {
...notification,
Expand Down Expand Up @@ -349,12 +340,6 @@ async function createAndroidBadgeOnlyNotification(
const { senderDeviceDescriptor, platformDetails, badge, threadID } =
inputData;

invariant(
(!threadID && badge) ||
hasMinCodeVersion(platformDetails, { native: FUTURE_CODE_VERSION }),
'thick thread badge updates not support for this client version',
);

let notificationData = { badgeOnly: '1' };
if (badge) {
notificationData = {
Expand Down
16 changes: 1 addition & 15 deletions lib/push/apns-notif-creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
prepareEncryptedAPNsSilentNotifications,
} from './crypto.js';
import { getAPNsNotificationTopic } from '../shared/notif-utils.js';
import {
hasMinCodeVersion,
FUTURE_CODE_VERSION,
} from '../shared/version-utils.js';
import { hasMinCodeVersion } from '../shared/version-utils.js';
import type { PlatformDetails } from '../types/device-types.js';
import { messageTypes } from '../types/message-types-enum.js';
import {
Expand Down Expand Up @@ -331,12 +328,6 @@ async function createAPNsNotificationRescind(
senderDeviceDescriptor,
} = inputData;
invariant(
(rescindID && badge !== null && badge !== undefined) ||
hasMinCodeVersion(platformDetails, { native: FUTURE_CODE_VERSION }),
'thick thread rescind not support for this client version',
);
const apnsTopic = getAPNsNotificationTopic(platformDetails);
let notification;
Expand Down Expand Up @@ -433,11 +424,6 @@ async function createAPNsBadgeOnlyNotification(
): Promise<$ReadOnlyArray<TargetedAPNsNotification>> {
const { senderDeviceDescriptor, platformDetails, threadID, badge } =
inputData;
invariant(
(!threadID && badge !== undefined && badge !== null) ||
hasMinCodeVersion(platformDetails, { native: FUTURE_CODE_VERSION }),
'thick thread badge updates not support for this client version',
);
const shouldBeEncrypted = hasMinCodeVersion(platformDetails, {
native: 222,
Expand Down
53 changes: 48 additions & 5 deletions lib/push/send-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import {
isMemberActive,
threadInfoFromRawThreadInfo,
} from '../shared/thread-utils.js';
import {
NEXT_CODE_VERSION,
hasMinCodeVersion,
} from '../shared/version-utils.js';
import type { AuxUserInfos } from '../types/aux-user-types.js';
import type { PlatformDetails, Platform } from '../types/device-types.js';
import {
Expand Down Expand Up @@ -997,6 +1001,38 @@ async function createOlmSessionWithDevices(
}
}

function filterDevicesSupportingDMNotifs<
T: { +devices: $ReadOnlyArray<Device>, ... },
>(devicesContainer: T): T {
return {
...devicesContainer,
devices: devicesContainer.devices.filter(({ platformDetails }) =>
hasMinCodeVersion(platformDetails, {
native: NEXT_CODE_VERSION,
web: NEXT_CODE_VERSION,
majorDesktop: NEXT_CODE_VERSION,
}),
),
};
}

function filterDevicesSupportingDMNotifsForUsers<
T: { +devices: $ReadOnlyArray<Device>, ... },
>(userToDevicesContainer: { +[userID: string]: T }): { +[userID: string]: T } {
const result: { [userID: string]: T } = {};
for (const userID in userToDevicesContainer) {
const devicesContainer = userToDevicesContainer[userID];
const filteredDevicesContainer =
filterDevicesSupportingDMNotifs(devicesContainer);
if (filteredDevicesContainer.devices.length === 0) {
continue;
}
result[userID] = filteredDevicesContainer;
}

return result;
}

type PreparePushNotifsInputData = {
+encryptedNotifUtilsAPI: EncryptedNotifUtilsAPI,
+senderDeviceDescriptor: SenderDeviceDescriptor,
Expand Down Expand Up @@ -1037,9 +1073,11 @@ async function preparePushNotifs(
return null;
}

const filteredPushInfos = filterDevicesSupportingDMNotifsForUsers(pushInfos);

const deviceIDsToUserIDs: { [string]: string } = {};
for (const userID in pushInfos) {
for (const device of pushInfos[userID].devices) {
for (const userID in filteredPushInfos) {
for (const device of filteredPushInfos[userID].devices) {
deviceIDsToUserIDs[device.cryptoID] = userID;
}
}
Expand All @@ -1049,7 +1087,7 @@ async function preparePushNotifs(
return await buildNotifsFromPushInfo({
encryptedNotifUtilsAPI,
senderDeviceDescriptor,
pushInfo: pushInfos,
pushInfo: filteredPushInfos,
thickRawThreadInfos,
userInfos,
getENSNames,
Expand Down Expand Up @@ -1084,15 +1122,20 @@ async function prepareOwnDevicesPushNotifs(
return null;
}

const filteredownDevicesPushInfos =
filterDevicesSupportingDMNotifs(ownDevicesPushInfo);

const { senderUserID, senderDeviceDescriptor } = senderInfo;
const deviceIDsToUserIDs: { [string]: string } = {};

for (const device of ownDevicesPushInfo.devices) {
for (const device of filteredownDevicesPushInfos.devices) {
deviceIDsToUserIDs[device.cryptoID] = senderUserID;
}

await createOlmSessionWithDevices(deviceIDsToUserIDs, olmSessionCreator);
const devicesByPlatform = getDevicesByPlatform(ownDevicesPushInfo.devices);
const devicesByPlatform = getDevicesByPlatform(
filteredownDevicesPushInfos.devices,
);

if (rescindData) {
return await buildRescindsForOwnDevices(
Expand Down

0 comments on commit 29f2689

Please sign in to comment.