Skip to content

Commit 36e006f

Browse files
committed
add TODOs
1 parent 4ffc256 commit 36e006f

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

apps/meteor/app/lib/server/functions/removeUserFromRoom.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,14 @@ import { notifyOnRoomChangedById, notifyOnSubscriptionChanged } from '../lib/not
1515
* Executes only the necessary database operations, with no callbacks, to prevent
1616
* propagation loops during external event processing.
1717
*/
18-
export const performUserRemoval = async function (rid: string, user: IUser, options?: { byUser?: IUser }): Promise<void> {
18+
export const performUserRemoval = async function (room: IRoom, user: IUser, options?: { byUser?: IUser }): Promise<void> {
1919
const subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, user._id, {
2020
projection: { _id: 1, status: 1 },
2121
});
2222
if (!subscription) {
2323
return;
2424
}
2525

26-
const room = await Rooms.findOneById(rid);
27-
28-
if (!room) {
29-
return;
30-
}
31-
3226
// TODO: move before callbacks to service
3327
await beforeLeaveRoomCallback.run(user, room);
3428

@@ -96,7 +90,7 @@ export const removeUserFromRoom = async function (rid: string, user: IUser, opti
9690

9791
await Room.beforeLeave(room);
9892

99-
await performUserRemoval(rid, user, options);
93+
await performUserRemoval(room, user, options);
10094

10195
await afterLeaveRoomCallback.run({ user, kicker: options?.byUser }, room);
10296

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export class RoomService extends ServiceClassInternal implements IRoomService {
8686
return removeUserFromRoom(roomId, user, options);
8787
}
8888

89-
async performUserRemoval(roomId: string, user: IUser, options?: { byUser?: IUser }): Promise<void> {
90-
return performUserRemoval(roomId, user, options);
89+
async performUserRemoval(room: IRoom, user: IUser, options?: { byUser?: IUser }): Promise<void> {
90+
return performUserRemoval(room, user, options);
9191
}
9292

9393
async performAcceptRoomInvite(room: IRoom, subscription: ISubscription, user: IUser & { username: string }): Promise<void> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
553553
return;
554554
}
555555

556-
await federationSDK.inviteUserToRoom(
556+
return federationSDK.inviteUserToRoom(
557557
userIdSchema.parse(`@${username}:${this.serverName}`),
558558
roomIdSchema.parse(room.federation.mrid),
559559
userIdSchema.parse(inviterUserId),

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async function getOrCreateFederatedUser(userId: string): Promise<IUser> {
3030
origin: userServerName,
3131
});
3232
} catch (error) {
33-
throw new Error(`Error getting or creating federated user ${userId}: ${error}`);
33+
logger.error(error, `Error getting or creating federated user ${userId}`);
34+
throw new Error(`Error getting or creating federated user ${userId}`);
3435
}
3536
}
3637

@@ -57,6 +58,8 @@ async function getOrCreateFederatedRoom({
5758
return room;
5859
}
5960

61+
// TODO room creator is not always the inviter
62+
6063
return Room.create(inviterUserId, {
6164
type: roomType,
6265
name: roomName,
@@ -71,7 +74,8 @@ async function getOrCreateFederatedRoom({
7174
},
7275
});
7376
} catch (error) {
74-
throw new Error(`Error getting or creating federated room ${roomName}: ${error}`);
77+
logger.error(error, `Error getting or creating federated room ${roomName}`);
78+
throw new Error(`Error getting or creating federated room ${roomName}`);
7579
}
7680
}
7781

@@ -208,17 +212,22 @@ async function handleLeave({
208212
room_id: roomId,
209213
state_key: userId,
210214
}: HomeserverEventSignatures['homeserver.matrix.membership']['event']): Promise<void> {
211-
const leavingUser = await getOrCreateFederatedUser(userId);
215+
const serverName = federationSDK.getConfig('serverName');
216+
const [username] = getUsernameServername(userId, serverName);
217+
218+
const leavingUser = await Users.findOneByUsername(username);
212219
if (!leavingUser) {
213-
throw new Error(`Failed to get or create leaving user: ${userId}`);
220+
return;
214221
}
215222

216223
const room = await Rooms.findOneFederatedByMrid(roomId);
217224
if (!room) {
218225
throw new Error(`Room not found while leaving user ${userId} from room ${roomId}`);
219226
}
220227

221-
await Room.performUserRemoval(room._id, leavingUser);
228+
await Room.performUserRemoval(room, leavingUser);
229+
230+
// TODO check if there are no pending invites to the room, and if so, delete the room
222231
}
223232

224233
export function member(emitter: Emitter<HomeserverEventSignatures>) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface IRoomService {
4444
},
4545
): Promise<boolean | undefined>;
4646
removeUserFromRoom(roomId: string, user: IUser, options?: { byUser: Pick<IUser, '_id' | 'username'> }): Promise<void>;
47-
performUserRemoval(roomId: string, user: IUser, options?: { byUser?: IUser }): Promise<void>;
47+
performUserRemoval(room: IRoom, user: IUser, options?: { byUser?: IUser }): Promise<void>;
4848
performAcceptRoomInvite(room: IRoom, subscription: ISubscription, user: IUser): Promise<void>;
4949
getValidRoomName(displayName: string, roomId?: string, options?: { allowDuplicates?: boolean }): Promise<string>;
5050
saveRoomTopic(

0 commit comments

Comments
 (0)