diff --git a/.changeset/witty-apples-pretend.md b/.changeset/witty-apples-pretend.md new file mode 100644 index 000000000000..cb4dd696983d --- /dev/null +++ b/.changeset/witty-apples-pretend.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixes async E2EE key exchange in development environments where change streams are no longer used diff --git a/apps/meteor/app/e2e/server/functions/handleSuggestedGroupKey.ts b/apps/meteor/app/e2e/server/functions/handleSuggestedGroupKey.ts index 22eccf03f407..e498d282d704 100644 --- a/apps/meteor/app/e2e/server/functions/handleSuggestedGroupKey.ts +++ b/apps/meteor/app/e2e/server/functions/handleSuggestedGroupKey.ts @@ -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', @@ -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); diff --git a/apps/meteor/app/e2e/server/methods/setUserPublicAndPrivateKeys.ts b/apps/meteor/app/e2e/server/methods/setUserPublicAndPrivateKeys.ts index 6ef35a063a28..45a00886af1e 100644 --- a/apps/meteor/app/e2e/server/methods/setUserPublicAndPrivateKeys.ts +++ b/apps/meteor/app/e2e/server/methods/setUserPublicAndPrivateKeys.ts @@ -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 { @@ -36,5 +38,7 @@ Meteor.methods({ const subscribedRoomIds = await Rooms.getSubscribedRoomIdsWithoutE2EKeys(userId); await Rooms.addUserIdToE2EEQueueByRoomIds(subscribedRoomIds, userId); + + void notifyOnRoomChangedById(subscribedRoomIds); }, }); diff --git a/apps/meteor/app/lib/server/functions/addUserToRoom.ts b/apps/meteor/app/lib/server/functions/addUserToRoom.ts index e6ca7b2a8b4d..2e74bf66cf4a 100644 --- a/apps/meteor/app/lib/server/functions/addUserToRoom.ts +++ b/apps/meteor/app/lib/server/functions/addUserToRoom.ts @@ -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'); } @@ -147,5 +145,6 @@ export const addUserToRoom = async function ( await Rooms.addUserIdToE2EEQueueByRoomIds([room._id], userToBeAdded._id); } + void notifyOnRoomChangedById(rid); return true; };