Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .changeset/seven-pugs-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed using real names on messages reactions
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ const MessageListProvider: VFC<MessageListProviderProps> = ({ children, scrollMe
return [];
}
if (!isMessageReactionsNormalized(message)) {
return message.reactions?.[reaction]?.usernames.filter((user) => user !== username).map((username) => `@${username}`) || [];
if (reactions?.[reaction]?.names) {
return (
(reactions?.[reaction]
?.names!.filter((_user, i) => reactions?.[reaction]?.usernames[i] !== username)
.filter((name) => name !== undefined) as string[]) || []
);
}

return reactions?.[reaction]?.usernames.filter((user) => user !== username).map((username) => `@${username}`) || [];
}
if (!username) {
return message.reactions[reaction].names;
Expand Down
31 changes: 26 additions & 5 deletions apps/meteor/server/modules/watchers/watchers.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function initWatchers(watcher: DatabaseWatcher, broadcast: BroadcastCallb
const getSettingCached = mem(async (setting: string): Promise<SettingValue> => Settings.getValueById(setting), { maxAge: 10000 });

const getUserNameCached = mem(
async (userId: string): Promise<string | undefined> => {
const user = await Users.findOne<Pick<IUser, 'name'>>(userId, { projection: { name: 1 } });
async (username: string): Promise<string | undefined> => {
const user = await Users.findOneByUsername<Pick<IUser, 'name'>>(username, { projection: { name: 1 } });
return user?.name;
},
{ maxAge: 10000 },
Expand All @@ -88,21 +88,42 @@ export function initWatchers(watcher: DatabaseWatcher, broadcast: BroadcastCallb
const UseRealName = (await getSettingCached('UI_Use_Real_Name')) === true;

if (UseRealName) {
if (message.u?._id) {
const name = await getUserNameCached(message.u._id);
if (message.u?.username) {
const name = await getUserNameCached(message.u.username);
if (name) {
message.u.name = name;
}
}

if (message.mentions?.length) {
for await (const mention of message.mentions) {
const name = await getUserNameCached(mention._id);
if (!mention.username) {
continue;
}

const name = await getUserNameCached(mention.username);
if (name) {
mention.name = name;
}
}
}

if (message.reactions) {
for await (const reaction of Object.keys(message.reactions)) {
const { usernames } = message.reactions[reaction];

if (!usernames) {
continue;
}

const namesPromises = usernames.map((username) => getUserNameCached(username));
const names = await Promise.all(namesPromises);

if (names) {
message.reactions[reaction].names = names;
}
}
}
}

void broadcast('watch.messages', { clientAction, message });
Expand Down