Skip to content

Commit 50cca84

Browse files
committed
make addUserToRoom to receive user as object instead of both obj and string
1 parent c1a136c commit 50cca84

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { notifyOnRoomChangedById, notifyOnSubscriptionChangedById } from '../lib
2121

2222
export const addUserToRoom = async (
2323
rid: string,
24-
user: Pick<IUser, '_id' | 'username'> | string,
24+
user: Pick<IUser, '_id' | 'username'>,
2525
inviter?: Pick<IUser, '_id' | 'username'>,
2626
{
2727
skipSystemMessage,
@@ -42,7 +42,7 @@ export const addUserToRoom = async (
4242
});
4343
}
4444

45-
const userToBeAdded = typeof user === 'string' ? await Users.findOneByUsername(user.replace('@', '')) : await Users.findOneById(user._id);
45+
const userToBeAdded = await Users.findOneById(user._id);
4646
const roomDirectives = roomCoordinator.getRoomDirectives(room.t);
4747

4848
if (!userToBeAdded) {

apps/meteor/app/lib/server/methods/addUsersToRoom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const addUsersToRoomMethod = async (userId: string, data: { rid: string;
9494

9595
const subscription = await Subscriptions.findOneByRoomIdAndUserId(data.rid, newUser._id);
9696
if (!subscription) {
97-
await addUserToRoom(data.rid, newUser || username, user);
97+
await addUserToRoom(data.rid, newUser);
9898
} else {
9999
if (!newUser.username) {
100100
return;
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { IUser, IRoom } from '@rocket.chat/core-typings';
1+
import type { IUser, IRoom, AtLeast } from '@rocket.chat/core-typings';
22

33
import { Callbacks } from './callbacksBase';
44

5-
export const beforeAddUserToRoom = Callbacks.create<(args: { user: IUser; inviter?: IUser }, room: IRoom) => void>('beforeAddUserToRoom');
5+
export const beforeAddUserToRoom =
6+
Callbacks.create<(args: { user: AtLeast<IUser, '_id' | 'username'>; inviter?: IUser }, room: IRoom) => void>('beforeAddUserToRoom');
67
export const beforeAddUsersToRoom =
78
Callbacks.create<(args: { usernames: string[]; inviter?: IUser }, room: IRoom) => void>('beforeAddUsersToRoom');

0 commit comments

Comments
 (0)