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:
@@ -421,6 +421,33 @@ describe("ChatModal: live", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("@everyone stands out only when the server flagged it", async () => {
|
||||
const { socket } = await setup();
|
||||
for (
|
||||
const [id, body, mentionsEveryone] of [
|
||||
["e1", "@everyone typed by anyone", undefined],
|
||||
["e2", "@everyone from a moderator", true],
|
||||
] as const
|
||||
) {
|
||||
socket.receive({
|
||||
type: "chat_message",
|
||||
message: wire(
|
||||
makeChatMessage({
|
||||
id,
|
||||
body,
|
||||
createdAt: new Date(),
|
||||
mentionsEveryone,
|
||||
}),
|
||||
),
|
||||
});
|
||||
}
|
||||
const row = (text: RegExp) =>
|
||||
screen.getByText(text).closest(".chat-message");
|
||||
expect(row(/typed by anyone/)).not.toHaveClass("chat-message--mention");
|
||||
expect(row(/from a moderator/)).toHaveClass("chat-message--mention");
|
||||
expect(screen.getByText("@everyone")).toHaveClass("md-everyone");
|
||||
});
|
||||
|
||||
test("an emoji-only message is shown large", async () => {
|
||||
await setup([makeChatMessage({ body: "🎉🎉" })]);
|
||||
expect(document.querySelector(".chat-message-text--jumbo"))
|
||||
|
||||
@@ -33,6 +33,18 @@ describe("Markdown", () => {
|
||||
expect(currentPath()).toBe("/@ann");
|
||||
});
|
||||
|
||||
test("@everyone links nowhere, and shows as a mention only when flagged", () => {
|
||||
md("hi @everyone");
|
||||
expect(screen.queryByRole("link")).toBeNull();
|
||||
expect(screen.getByText("hi @everyone")).toBeInTheDocument();
|
||||
renderWithContexts(<Markdown everyone>{"yo @Everyone and @ann"}</Markdown>);
|
||||
expect(screen.getByText("@Everyone")).toHaveClass("md-everyone");
|
||||
expect(screen.getByRole("link", { name: "@ann" })).toHaveAttribute(
|
||||
"href",
|
||||
"/@ann",
|
||||
);
|
||||
});
|
||||
|
||||
test("mentions in code and inside URLs are left alone", () => {
|
||||
md("`@ann` and https://mastodon.social/@bob");
|
||||
expect(screen.getByText("@ann").tagName).toBe("CODE");
|
||||
|
||||
@@ -29,9 +29,9 @@ describe("useMentionAutocomplete", () => {
|
||||
{ id: "3", username: "albert", avatarMime: null },
|
||||
];
|
||||
|
||||
function setup() {
|
||||
function setup(everyone = false) {
|
||||
const replace = vi.fn();
|
||||
const hook = renderHook(() => useMentionAutocomplete(replace));
|
||||
const hook = renderHook(() => useMentionAutocomplete(replace, everyone));
|
||||
const type = async (value: string, cursor = value.length) => {
|
||||
act(() => hook.result.current.syncMention(value, cursor, true));
|
||||
await act(() => vi.advanceTimersByTimeAsync(200));
|
||||
@@ -56,6 +56,21 @@ describe("useMentionAutocomplete", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("offers @everyone first, only when allowed", async () => {
|
||||
route("GET /api/users", () => [users[0]]);
|
||||
const allowed = setup(true);
|
||||
await allowed.type("@E");
|
||||
expect(allowed.hook.result.current.mentionResults.map((u) => u.username))
|
||||
.toEqual(["everyone", "alice"]);
|
||||
await allowed.type("@al");
|
||||
expect(allowed.hook.result.current.mentionResults.map((u) => u.username))
|
||||
.toEqual(["alice"]);
|
||||
const denied = setup();
|
||||
await denied.type("@e");
|
||||
expect(denied.hook.result.current.mentionResults.map((u) => u.username))
|
||||
.toEqual(["alice"]);
|
||||
});
|
||||
|
||||
test("debounces keystrokes into one lookup", async () => {
|
||||
route("GET /api/users", () => users);
|
||||
const { hook } = setup();
|
||||
|
||||
@@ -134,6 +134,17 @@ const n = {
|
||||
contextTitle: "",
|
||||
},
|
||||
}),
|
||||
mentionEveryone: makeNotification({
|
||||
type: "user_mentioned",
|
||||
data: {
|
||||
mentionerId: "m",
|
||||
mentionerUsername: "mo",
|
||||
contextType: "chat",
|
||||
contextId: "y",
|
||||
contextTitle: "",
|
||||
everyone: true,
|
||||
},
|
||||
}),
|
||||
mentionPlaylist: makeNotification({
|
||||
type: "user_mentioned",
|
||||
data: {
|
||||
@@ -170,8 +181,9 @@ describe("Notifications", () => {
|
||||
"/notifications?chat=x",
|
||||
"/@bob/playlists/faves",
|
||||
]);
|
||||
expect(await link(/mentioned everyone in/)).toBe("/notifications?chat=y");
|
||||
expect(screen.getByText("a comment")).toBeInTheDocument();
|
||||
expect(screen.getByText("the chat")).toBeInTheDocument();
|
||||
expect(screen.getAllByText("the chat")).toHaveLength(2);
|
||||
expect(screen.getByText("Faves")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user