Skip to content
Open
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
15 changes: 12 additions & 3 deletions apps/meteor/app/lib/server/methods/addUsersToRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { addUserToRoom } from '../functions/addUserToRoom';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
addUsersToRoom(data: { rid: string; users: string[] }): boolean;
addUsersToRoom(data: { rid: string; users: string[] }): { added: number; alreadyInRoom: number; total: number };
}
}

Expand All @@ -27,7 +27,7 @@ export const sanitizeUsername = (username: string) => {
return username.replace(/(^@)|( @)/, '');
};

export const addUsersToRoomMethod = async (userId: string, data: { rid: string; users: string[] }, user?: IUser): Promise<boolean> => {
export const addUsersToRoomMethod = async (userId: string, data: { rid: string; users: string[] }, user?: IUser): Promise<{ added: number; alreadyInRoom: number; total: number }> => {
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'addUsersToRoom',
Expand Down Expand Up @@ -86,6 +86,9 @@ export const addUsersToRoomMethod = async (userId: string, data: { rid: string;

await beforeAddUsersToRoom.run({ usernames: data.users, inviter: user }, room);

let addedCount = 0;
let alreadyInRoomCount = 0;

await Promise.all(
data.users.map(async (username) => {
const newUser = await Users.findOneByUsernameIgnoringCase(sanitizeUsername(username));
Expand All @@ -104,7 +107,9 @@ export const addUsersToRoomMethod = async (userId: string, data: { rid: string;
const subscription = await Subscriptions.findOneByRoomIdAndUserId(data.rid, newUser._id);
if (!subscription) {
await addUserToRoom(data.rid, newUser, user);
addedCount++;
} else {
alreadyInRoomCount++;
if (!newUser.username) {
return;
}
Expand All @@ -119,7 +124,11 @@ export const addUsersToRoomMethod = async (userId: string, data: { rid: string;
}),
);

return true;
return {
added: addedCount,
alreadyInRoom: alreadyInRoomCount,
total: data.users.length,
};
};

Meteor.methods<ServerMethods>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,21 @@ const AddUsers = ({ rid, onClickBack, reload }: AddUsersProps): ReactElement =>

const handleSave = useEffectEvent(async ({ users }: { users: string[] }) => {
try {
await saveAction({ rid, users });
dispatchToastMessage({ type: 'success', message: t(roomIsFederated && !isFederationBlocked ? 'Users_invited' : 'Users_added') });
const result = await saveAction({ rid, users });

// Determine the appropriate message based on the results
let message: string;
if (result.added === 0 && result.alreadyInRoom > 0) {
message = t('All_users_are_already_in_this_room');
} else if (result.added > 0 && result.alreadyInRoom > 0) {
message = t('Some_users_added_others_already_in_room', { added: result.added, total: result.total });
} else if (result.added > 0) {
message = t(roomIsFederated && !isFederationBlocked ? 'Users_invited' : 'Users_added');
} else {
message = t('Users_added');
Comment on lines +60 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that translation keys are defined.

The implementation references several translation keys, including what appear to be new ones:

  • All_users_are_already_in_this_room (line 60)
  • Some_users_added_others_already_in_room (line 62)

Ensure these keys are defined in the i18n translation files for all supported languages.

Run the following script to check if these translation keys exist:


🏁 Script executed:

#!/bin/bash
# Description: Check for translation key definitions

# Search for new translation keys in i18n files
echo "Checking for 'All_users_are_already_in_this_room':"
rg -n "All_users_are_already_in_this_room" --type=json

echo -e "\nChecking for 'Some_users_added_others_already_in_room':"
rg -n "Some_users_added_others_already_in_room" --type=json

Length of output: 107


🏁 Script executed:

#!/bin/bash
# Description: Comprehensive translation key verification

echo "=== Finding i18n/translation directories ==="
fd -t d "i18n|lang|locale|translation" --type d

echo -e "\n=== Searching for existing key 'Users_added' in all files ==="
rg -n "Users_added" -C2 | head -30

echo -e "\n=== Searching for new key 'All_users_are_already_in_this_room' in all file types ==="
rg -n "All_users_are_already_in_this_room" | head -20

echo -e "\n=== Searching for new key 'Some_users_added_others_already_in_room' in all file types ==="
rg -n "Some_users_added_others_already_in_room" | head -20

echo -e "\n=== Checking file structure of public/locales or similar ==="
fd -t f "\.json$" -g "*locale*" -g "*lang*" -g "*i18n*" | head -20

Length of output: 3399


🏁 Script executed:

#!/bin/bash
# Description: Check English locale files for translation keys

echo "=== Checking English locale files ==="
find packages/i18n/src/locales -name "*en*" -type f

echo -e "\n=== Searching for new keys in en.i18n.json ==="
rg -n "All_users_are_already_in_this_room|Some_users_added_others_already_in_room|Users_added" packages/i18n/src/locales/en.i18n.json

echo -e "\n=== Sample of en.i18n.json around 'Users' keys ==="
rg -n "\"Users" packages/i18n/src/locales/en.i18n.json -A1 -B1 | head -40

Length of output: 2983


Add missing translation keys to i18n locale files.

The code references two translation keys that are not defined in the i18n files:

  • All_users_are_already_in_this_room (line 60)
  • Some_users_added_others_already_in_room (line 62)

These keys must be added to all locale files in packages/i18n/src/locales/ (at minimum to en.i18n.json, then propagated to other language files).

🤖 Prompt for AI Agents
In apps/meteor/client/views/room/contextualBar/RoomMembers/AddUsers/AddUsers.tsx
around lines 60 to 66, the code uses two translation keys that are missing from
the i18n locale files; add "All_users_are_already_in_this_room" and
"Some_users_added_others_already_in_room" to
packages/i18n/src/locales/en.i18n.json (with appropriate English strings, e.g.
"All users are already in this room" and "Added {{added}} of {{total}} users;
others were already in the room"), then propagate these keys and translations to
all other locale files under packages/i18n/src/locales/, run the i18n
build/validation step if present, and ensure the interpolation placeholders
match the code (added, total).

}

dispatchToastMessage({ type: 'success', message });
onClickBack();
reload();
} catch (error) {
Expand Down