Skip to content

Commit

Permalink
fix: Async E2EE key exchange not working on develop (#33378)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman authored Sep 30, 2024
1 parent bc1e6ee commit 662aca3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-apples-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes async E2EE key exchange in development environments where change streams are no longer used
12 changes: 9 additions & 3 deletions apps/meteor/app/e2e/server/functions/handleSuggestedGroupKey.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Rooms, Subscriptions } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { notifyOnSubscriptionChangedById } from '../../../lib/server/lib/notifyListener';
import { notifyOnSubscriptionChangedById, notifyOnRoomChangedById } from '../../../lib/server/lib/notifyListener';

export async function handleSuggestedGroupKey(
handle: 'accept' | 'reject',
Expand All @@ -25,11 +25,17 @@ export async function handleSuggestedGroupKey(

if (handle === 'accept') {
await Subscriptions.setGroupE2EKey(sub._id, suggestedKey);
await Rooms.removeUsersFromE2EEQueueByRoomId(sub.rid, [userId]);
const { modifiedCount } = await Rooms.removeUsersFromE2EEQueueByRoomId(sub.rid, [userId]);
if (modifiedCount) {
void notifyOnRoomChangedById(sub.rid);
}
}

if (handle === 'reject') {
await Rooms.addUserIdToE2EEQueueByRoomIds([sub.rid], userId);
const { modifiedCount } = await Rooms.addUserIdToE2EEQueueByRoomIds([sub.rid], userId);
if (modifiedCount) {
void notifyOnRoomChangedById(sub.rid);
}
}

const { modifiedCount } = await Subscriptions.unsetGroupE2ESuggestedKey(sub._id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Rooms, Users } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { notifyOnRoomChangedById } from '../../../lib/server/lib/notifyListener';

declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
Expand Down Expand Up @@ -36,5 +38,7 @@ Meteor.methods<ServerMethods>({

const subscribedRoomIds = await Rooms.getSubscribedRoomIdsWithoutE2EKeys(userId);
await Rooms.addUserIdToE2EEQueueByRoomIds(subscribedRoomIds, userId);

void notifyOnRoomChangedById(subscribedRoomIds);
},
});
3 changes: 1 addition & 2 deletions apps/meteor/app/lib/server/functions/addUserToRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export const addUserToRoom = async function (
void notifyOnSubscriptionChangedById(insertedId, 'inserted');
}

void notifyOnRoomChangedById(rid);

if (!userToBeAdded.username) {
throw new Meteor.Error('error-invalid-user', 'Cannot add an user to a room without a username');
}
Expand Down Expand Up @@ -147,5 +145,6 @@ export const addUserToRoom = async function (
await Rooms.addUserIdToE2EEQueueByRoomIds([room._id], userToBeAdded._id);
}

void notifyOnRoomChangedById(rid);
return true;
};

0 comments on commit 662aca3

Please sign in to comment.