Skip to content

Commit

Permalink
fix: Server not notifying users of E2EE key suggestions (#33435)
Browse files Browse the repository at this point in the history
Co-authored-by: Ricardo Garim <9621276+ricardogarim@users.noreply.github.com>
  • Loading branch information
KevLehman and ricardogarim authored Oct 8, 2024
1 parent a16b582 commit d9fe5bb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/pink-wombats-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/model-typings": patch
---

Fixes an issue causing server to not notify users via websocket of new E2EE keys suggested by other users to them when running in development environments.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { IRoom, IUser } from '@rocket.chat/core-typings';
import { Rooms, Subscriptions } from '@rocket.chat/models';

import { canAccessRoomIdAsync } from '../../../authorization/server/functions/canAccessRoom';
import { notifyOnSubscriptionChanged, notifyOnRoomChangedById } from '../../../lib/server/lib/notifyListener';

export const provideUsersSuggestedGroupKeys = async (
userId: IUser['_id'],
Expand All @@ -21,13 +22,15 @@ export const provideUsersSuggestedGroupKeys = async (

const usersWithSuggestedKeys = [];
for await (const user of usersSuggestedGroupKeys[roomId]) {
const { modifiedCount } = await Subscriptions.setGroupE2ESuggestedKey(user._id, roomId, user.key);
if (!modifiedCount) {
const { value } = await Subscriptions.setGroupE2ESuggestedKey(user._id, roomId, user.key);
if (!value) {
continue;
}
void notifyOnSubscriptionChanged(value);
usersWithSuggestedKeys.push(user._id);
}

await Rooms.removeUsersFromE2EEQueueByRoomId(roomId, usersWithSuggestedKeys);
void notifyOnRoomChangedById(roomId);
}
};
8 changes: 4 additions & 4 deletions apps/meteor/app/e2e/server/methods/updateGroupKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Subscriptions } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { notifyOnSubscriptionChangedById, notifyOnSubscriptionChangedByRoomIdAndUserId } from '../../../lib/server/lib/notifyListener';
import { notifyOnSubscriptionChangedById, notifyOnSubscriptionChanged } from '../../../lib/server/lib/notifyListener';

declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -34,9 +34,9 @@ Meteor.methods<ServerMethods>({
}

// uid also has subscription to this room
const { modifiedCount } = await Subscriptions.setGroupE2ESuggestedKey(uid, rid, key);
if (modifiedCount) {
void notifyOnSubscriptionChangedByRoomIdAndUserId(rid, uid);
const { value } = await Subscriptions.setGroupE2ESuggestedKey(uid, rid, key);
if (value) {
void notifyOnSubscriptionChanged(value);
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/server/models/raw/Subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
AggregationCursor,
CountDocumentsOptions,
DeleteOptions,
ModifyResult,
} from 'mongodb';

import { getDefaultSubscriptionPref } from '../../../app/utils/lib/getDefaultSubscriptionPref';
Expand Down Expand Up @@ -585,10 +586,10 @@ export class SubscriptionsRaw extends BaseRaw<ISubscription> implements ISubscri
return this.updateOne(query, update);
}

setGroupE2ESuggestedKey(uid: string, rid: string, key: string): Promise<UpdateResult> {
setGroupE2ESuggestedKey(uid: string, rid: string, key: string): Promise<ModifyResult<ISubscription>> {
const query = { rid, 'u._id': uid };
const update = { $set: { E2ESuggestedKey: key } };
return this.updateOne(query, update);
return this.findOneAndUpdate(query, update, { returnDocument: 'after' });
}

unsetGroupE2ESuggestedKey(_id: string): Promise<UpdateResult | Document> {
Expand Down
3 changes: 2 additions & 1 deletion packages/model-typings/src/models/ISubscriptionsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
AggregationCursor,
DeleteOptions,
CountDocumentsOptions,
ModifyResult,
} from 'mongodb';

import type { IBaseModel } from './IBaseModel';
Expand Down Expand Up @@ -115,7 +116,7 @@ export interface ISubscriptionsModel extends IBaseModel<ISubscription> {

setGroupE2EKey(_id: string, key: string): Promise<UpdateResult>;

setGroupE2ESuggestedKey(uid: string, rid: string, key: string): Promise<UpdateResult>;
setGroupE2ESuggestedKey(uid: string, rid: string, key: string): Promise<ModifyResult<ISubscription>>;

unsetGroupE2ESuggestedKey(_id: string): Promise<UpdateResult | Document>;

Expand Down

0 comments on commit d9fe5bb

Please sign in to comment.