fix <> wrapper

pull/1154/head
NanoAim 2025-07-10 12:08:58 +08:00
parent 8e55d8681d
commit bb86cdfdbf
1 changed files with 25 additions and 7 deletions

View File

@ -329,6 +329,21 @@ export default observer(({ channel }: Props) => {
if (uploadState.type !== "none") return sendFile(content);
if (content.length === 0) return;
// Check for @everyone mentions first
if (content.includes("@everyone")) {
// Check if user has permission to mention everyone
if (!channel.havePermission("MentionEveryone")) {
// Display error toast when no permission
modalController.push({
type: "error",
error: client.i18n.t("app.main.channel.misc.no_everyone_mention"),
});
// Remove @everyone from the message when no permission
content = content.replace(/@everyone/g, "everyone");
}
// If user has permission, keep @everyone as is (don't wrap in <>)
}
// Convert @username mentions to <@USER_ID> format
const mentionRegex = /@([a-zA-Z0-9_]+)/g;
const mentionMatches = content.match(mentionRegex);
@ -336,14 +351,17 @@ export default observer(({ channel }: Props) => {
if (mentionMatches) {
for (const mention of mentionMatches) {
const username = mention.substring(1); // Remove the @ symbol
// Find the user with this username
const user = Array.from(client.users.values()).find(
(u) => u.username.toLowerCase() === username.toLowerCase()
);
// Make sure it's not 'everyone' (already handled)
if (username.toLowerCase() !== "everyone") {
// Find the user with this username
const user = Array.from(client.users.values()).find(
(u) => u.username.toLowerCase() === username.toLowerCase()
);
if (user) {
// Replace @username with <@USER_ID>
content = content.replace(mention, `<@${user._id}>`);
if (user) {
// Replace @username with <@USER_ID>
content = content.replace(mention, `<@${user._id}>`);
}
}
}
}