v4: a moderator's or an admin's @everyone in the chat notifies every user — there was no way to reach everyone at once. The new chat:everyone permission, held by moderators and admins, lets a chat message saying @everyone notify every user but its author and those reading the chat, through notifyEveryone, after notifyMentions, so a user also named is told once, by name; the notification is a user_mentioned with everyone set, which the notifications page and the digest word as "mentioned everyone in the chat". chat_messages.mentions_everyone, sent as ChatMessage.mentionsEveryone, is set from the author's role each time the body is written, so a user's @everyone reaches no one, a moderator's edit of a user's message can't make it reach everyone, and a demoted author's next edit loses it. Only an edit that adds @everyone notifies, so fixing an announcement's typo reaches no one new. The client highlights and chimes by the flag, never by the text; Markdown shows @everyone as a mention only in a flagged message, and never links it to a profile. The chat composer offers @everyone first to those who may say it. No account may be named everyone, in any case: migration 0023 adds the column, flags the moderators' and admins' past @everyone messages, renames a user named everyone to everyone_N and drops an alias everyone. 265 backend tests and 681 frontend tests pass, and deno check, tsc, eslint, doc:lint and i18n:compile --strict are clean; checked in screenshots of the chat at 1280 and 390px, with a moderator's and a user's @everyone and the suggestions open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
type WsClient,
|
||||
} from "../services/ws-service.ts";
|
||||
import {
|
||||
chatMessageMentionsEveryone,
|
||||
createChatMessage,
|
||||
deleteChatMessage,
|
||||
getChatReadState,
|
||||
@@ -42,6 +43,7 @@ import {
|
||||
} from "../services/chat-service.ts";
|
||||
import {
|
||||
getUnreadCount,
|
||||
notifyEveryone,
|
||||
notifyMentions,
|
||||
} from "../services/notification-service.ts";
|
||||
import { hasPermission } from "../../shared/permissions.ts";
|
||||
@@ -369,7 +371,8 @@ function optionalString(value: unknown, maxLength: number): string | undefined {
|
||||
|
||||
/**
|
||||
* Handles `chat_send`. It stores the message, broadcasts it, and notifies the
|
||||
* @mentioned users who aren't reading the chat.
|
||||
* @mentioned users who aren't reading the chat, and everyone who isn't when
|
||||
* the message is flagged `mentionsEveryone`.
|
||||
*/
|
||||
function handleChatSend(
|
||||
client: WsClient,
|
||||
@@ -404,6 +407,9 @@ function handleChatSend(
|
||||
undefined,
|
||||
isUserChatOpen,
|
||||
);
|
||||
if (message.mentionsEveryone) {
|
||||
notifyEveryone(userId, message.id, isUserChatOpen);
|
||||
}
|
||||
} catch (err) {
|
||||
sendChatError(
|
||||
client,
|
||||
@@ -430,7 +436,8 @@ function canModerateChat(client: WsClient): boolean {
|
||||
|
||||
/**
|
||||
* Handles `chat_edit`. It stores the new body, broadcasts it, and notifies, in
|
||||
* the author's name, the users the edit newly mentions.
|
||||
* the author's name, the users the edit newly mentions, and everyone when the
|
||||
* edit adds a `@everyone` the author may say.
|
||||
*/
|
||||
function handleChatEdit(client: WsClient, id: unknown, body: unknown): void {
|
||||
const userId = chatWriter(client);
|
||||
@@ -441,6 +448,10 @@ function handleChatEdit(client: WsClient, id: unknown, body: unknown): void {
|
||||
}
|
||||
|
||||
try {
|
||||
// Only an edit that adds `@everyone` notifies everyone: fixing a typo in
|
||||
// an announcement mustn't reach those who had the chat open when it was
|
||||
// sent, nor those who joined since.
|
||||
const wasEveryone = chatMessageMentionsEveryone(id);
|
||||
const message = updateChatMessage(
|
||||
id,
|
||||
body,
|
||||
@@ -460,6 +471,9 @@ function handleChatEdit(client: WsClient, id: unknown, body: unknown): void {
|
||||
undefined,
|
||||
isUserChatOpen,
|
||||
);
|
||||
if (message.mentionsEveryone && !wasEveryone) {
|
||||
notifyEveryone(message.userId, message.id, isUserChatOpen);
|
||||
}
|
||||
} catch (err) {
|
||||
sendChatError(
|
||||
client,
|
||||
|
||||
Reference in New Issue
Block a user