Skip to content

Commit 7288d3d

Browse files
committed
regression(federation): fix not able to accept mixed DM invite
1 parent 8448179 commit 7288d3d

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

apps/meteor/server/services/room/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { removeRoomOwner } from '../../methods/removeRoomOwner';
3636
export class RoomService extends ServiceClassInternal implements IRoomService {
3737
protected name = 'room';
3838

39-
async updateDirectMessageRoomName(room: IRoom): Promise<boolean> {
39+
async updateDirectMessageRoomName(room: IRoom, ignoreStatusFromSubs?: string[]): Promise<boolean> {
4040
const subs = await Subscriptions.findByRoomId(room._id, { projection: { u: 1, status: 1 } }).toArray();
4141

4242
const uids = subs.map((sub) => sub.u._id);
@@ -47,7 +47,7 @@ export class RoomService extends ServiceClassInternal implements IRoomService {
4747

4848
for await (const sub of subs) {
4949
// don't update the name if the user is invited but hasn't accepted yet
50-
if (sub.status === 'INVITED') {
50+
if (!ignoreStatusFromSubs?.includes(sub._id) && sub.status === 'INVITED') {
5151
continue;
5252
}
5353
await Subscriptions.updateOne({ _id: sub._id }, { $set: roomNames[sub.u._id] });

ee/packages/federation-matrix/src/FederationMatrix.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,9 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
291291
continue;
292292
}
293293

294-
if (!isUserNativeFederated(member)) {
295-
continue;
296-
}
297-
298294
try {
299295
await federationSDK.inviteUserToRoom(
300-
userIdSchema.parse(member.username),
296+
isUserNativeFederated(member) ? userIdSchema.parse(member.username) : `@${member.username}:${this.serverName}`,
301297
roomIdSchema.parse(matrixRoomResult.room_id),
302298
userIdSchema.parse(actualMatrixUserId),
303299
);
@@ -919,8 +915,6 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
919915

920916
if (action === 'accept') {
921917
await federationSDK.acceptInvite(room.federation.mrid, matrixUserId);
922-
923-
await Room.performAcceptRoomInvite(room, subscription, user);
924918
}
925919

926920
if (action === 'reject') {

ee/packages/federation-matrix/src/events/member.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async function handleJoin({
215215

216216
// update room name for DMs
217217
if (room.t === 'd') {
218-
await Room.updateDirectMessageRoomName(room);
218+
await Room.updateDirectMessageRoomName(room, [subscription._id]);
219219
}
220220

221221
if (!subscription.status) {

ee/packages/federation-matrix/tests/end-to-end/dms.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ const waitForRoomEvent = async (
10971097
});
10981098
});
10991099

1100-
it.failing('should accept the invitation by the Rocket.Chat user', async () => {
1100+
it('should accept the invitation by the Rocket.Chat user', async () => {
11011101
const response = await acceptRoomInvite(rcRoom._id, rcUserConfig2);
11021102
expect(response.success).toBe(true);
11031103
});
@@ -1435,7 +1435,7 @@ const waitForRoomEvent = async (
14351435
});
14361436
});
14371437

1438-
it.failing('should create a federated DM between rcUser1 and rcUser2 and the Synapse user', async () => {
1438+
it('should create a federated DM between rcUser1 and rcUser2 and the Synapse user', async () => {
14391439
const fedDmResponse = await rcUser1.config.request
14401440
.post(api('dm.create'))
14411441
.set(rcUser1.config.credentials)
@@ -1486,7 +1486,6 @@ const waitForRoomEvent = async (
14861486
{ delayMs: 100 },
14871487
);
14881488

1489-
// TODO accept not working
14901489
const response = await acceptRoomInvite(rcRoom._id, rcUser2.config);
14911490
expect(response.success).toBe(true);
14921491
});

packages/core-services/src/types/IRoomService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ export interface IRoomService {
6969
status?: 'INVITED';
7070
roles?: ISubscription['roles'];
7171
}): Promise<string | undefined>;
72-
updateDirectMessageRoomName(room: IRoom): Promise<boolean>;
72+
updateDirectMessageRoomName(room: IRoom, ignoreStatusFromSubs?: string[]): Promise<boolean>;
7373
}

0 commit comments

Comments
 (0)