diff --git a/src/components/common/messaging/MessageBox.tsx b/src/components/common/messaging/MessageBox.tsx index 2e7294e0..ffb5d366 100644 --- a/src/components/common/messaging/MessageBox.tsx +++ b/src/components/common/messaging/MessageBox.tsx @@ -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}>`); + } } } }