Skip to content

Fix multiple mentions rendered incorrectly #2283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VNDRN opened this issue Nov 3, 2023 · 5 comments · Fixed by #2286
Closed

Fix multiple mentions rendered incorrectly #2283

VNDRN opened this issue Nov 3, 2023 · 5 comments · Fixed by #2286
Labels
Bug Something isn't working in the SDK released

Comments

@VNDRN
Copy link

VNDRN commented Nov 3, 2023

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

When rendering mentioned users, I noticed a bug. It's fine if you mention a single user in a message, but when you mention multiple, they get rendered as plain text. I dug into the code and noticed that the separator used between the mentions | is also being escaped. A fix for this is to escape the user names instead of the entire string.

Here is the diff that solved my problem:

diff --git a/node_modules/stream-chat-react-native-core/src/components/Message/MessageSimple/utils/renderText.tsx b/node_modules/stream-chat-react-native-core/src/components/Message/MessageSimple/utils/renderText.tsx
index e533655..bfaba5d 100644
--- a/node_modules/stream-chat-react-native-core/src/components/Message/MessageSimple/utils/renderText.tsx
+++ b/node_modules/stream-chat-react-native-core/src/components/Message/MessageSimple/utils/renderText.tsx
@@ -224,9 +224,9 @@ export const renderText = <
     ? mentioned_users.reduce((acc, cur) => {
         const userName = cur.name || cur.id || '';
         if (userName) {
-          acc += `${acc.length ? '|' : ''}@${userName}`;
+          acc += `${acc.length ? '|' : ''}@${userName.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&')}`;
         }
-        return acc.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&');
+        return acc;
       }, '')
     : '';

Hope this can get merged into an upcoming release.

This issue body was partially generated by patch-package.

@vishalnarkhede
Copy link
Contributor

@khushal87 could you please take care of this? Please make sure to use replace instead of replaceAll. #2253

@khushal87
Copy link
Member

Yes for sure @vishalnarkhede

@VNDRN
Copy link
Author

VNDRN commented Nov 3, 2023

Just wanted to mention (no pun intended) that when a username is an email address, it gets resolved as a link instead of a mention. Would be great if this could get fixed too 😄

@khushal87
Copy link
Member

username is an email address; it gets resolved as a link instead of a mention

Created a new issue for this as it will need some separate attention and should not block this original issue.

@stream-ci-bot
Copy link
Contributor

🎉 This issue has been resolved in version 5.20.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working in the SDK released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants