Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Async E2EE key exchange not working on develop #33378

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
Loading