From 252d33f001962a6b4b085958540c7c9f1cc0f5a7 Mon Sep 17 00:00:00 2001 From: NanoAim <65581271+NanoAim@users.noreply.github.com> Date: Sat, 5 Jul 2025 12:59:15 +0800 Subject: [PATCH] everyone --- external/lang | 2 +- external/revolt.js | 2 +- src/components/common/messaging/Message.tsx | 7 +++-- src/components/markdown/RemarkRenderer.tsx | 4 ++- src/components/markdown/hast.ts | 2 +- src/components/markdown/plugins/mentions.tsx | 30 ++++++++++++++++++-- src/mobx/State.ts | 16 +++++++++++ src/mobx/stores/NotificationOptions.ts | 3 +- 8 files changed, 56 insertions(+), 10 deletions(-) diff --git a/external/lang b/external/lang index 8ecb9a34..7f1f53ad 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit 8ecb9a34b1b459b5280a6351a4044dfa44b68019 +Subproject commit 7f1f53ad388f9e3eab1533556d2918c66918790d diff --git a/external/revolt.js b/external/revolt.js index 64121957..3cd1f4ec 160000 --- a/external/revolt.js +++ b/external/revolt.js @@ -1 +1 @@ -Subproject commit 64121957a7eb97cb0eb3c0aba20541fecab4d934 +Subproject commit 3cd1f4ec377bb11ca8cfeab6dcd48e37d0cdbdfb diff --git a/src/components/common/messaging/Message.tsx b/src/components/common/messaging/Message.tsx index 497db9e2..e32c33d6 100644 --- a/src/components/common/messaging/Message.tsx +++ b/src/components/common/messaging/Message.tsx @@ -120,9 +120,10 @@ const Message = observer( contrast={contrast} sending={typeof queued !== "undefined"} mention={ - message.mention_ids && client.user - ? message.mention_ids.includes(client.user._id) - : undefined + client.user && ( + (message.mention_ids?.includes(client.user._id)) || + (message as any).mentionsEveryone + ) || undefined } failed={typeof queued?.error !== "undefined"} {...(attachContext diff --git a/src/components/markdown/RemarkRenderer.tsx b/src/components/markdown/RemarkRenderer.tsx index d01ed9b6..4388749c 100644 --- a/src/components/markdown/RemarkRenderer.tsx +++ b/src/components/markdown/RemarkRenderer.tsx @@ -23,7 +23,7 @@ import { RenderAnchor } from "./plugins/anchors"; import { remarkChannels, RenderChannel } from "./plugins/channels"; import { isOnlyEmoji, remarkEmoji, RenderEmoji } from "./plugins/emoji"; import { remarkHtmlToText } from "./plugins/htmlToText"; -import { remarkMention, RenderMention } from "./plugins/mentions"; +import { remarkMention, RenderMention, remarkEveryone, RenderEveryoneMention } from "./plugins/mentions"; import { remarkSpoiler, RenderSpoiler } from "./plugins/spoiler"; import { remarkTimestamps } from "./plugins/timestamps"; import "./prism"; @@ -39,6 +39,7 @@ const Null: React.FC = () => null; const components = { emoji: RenderEmoji, mention: RenderMention, + everyone: RenderEveryoneMention, spoiler: RenderSpoiler, channel: RenderChannel, a: RenderAnchor, @@ -143,6 +144,7 @@ const render = unified() .use(remarkTimestamps) .use(remarkEmoji) .use(remarkMention) + .use(remarkEveryone) .use(remarkHtmlToText) .use(remarkRehype, { handlers, diff --git a/src/components/markdown/hast.ts b/src/components/markdown/hast.ts index d2054aff..a1e7a3b9 100644 --- a/src/components/markdown/hast.ts +++ b/src/components/markdown/hast.ts @@ -2,6 +2,6 @@ import { passThroughComponents } from "./plugins/remarkRegexComponent"; import { timestampHandler } from "./plugins/timestamps"; export const handlers = { - ...passThroughComponents("emoji", "spoiler", "mention", "channel"), + ...passThroughComponents("emoji", "spoiler", "mention", "channel", "everyone"), timestamp: timestampHandler, }; diff --git a/src/components/markdown/plugins/mentions.tsx b/src/components/markdown/plugins/mentions.tsx index eae6938b..c201f374 100644 --- a/src/components/markdown/plugins/mentions.tsx +++ b/src/components/markdown/plugins/mentions.tsx @@ -1,6 +1,5 @@ -import { RE_MENTIONS } from "revolt.js"; +import { RE_MENTIONS, RE_EVERYONE } from "revolt.js"; import styled from "styled-components"; - import { clientController } from "../../../controllers/client/ClientController"; import UserShort from "../../common/user/UserShort"; import { createComponent, CustomComponentProps } from "./remarkRegexComponent"; @@ -48,6 +47,33 @@ export function RenderMention({ match }: CustomComponentProps) { ); } +const EveryoneMention = styled.span` + padding: 0 4px; + flex-shrink: 0; + + font-weight: 600; + cursor: default; + color: var(--foreground); + background: var(--secondary-background); + border-radius: calc(var(--border-radius) * 2); + + transition: 0.1s ease filter; + + &:hover { + filter: brightness(0.75); + } +`; + +export function RenderEveryoneMention() { + return ( + + @everyone + + ); +} + export const remarkMention = createComponent("mention", RE_MENTIONS, (match) => clientController.getAvailableClient().users.has(match), ); + +export const remarkEveryone = createComponent("everyone", RE_EVERYONE, () => true); diff --git a/src/mobx/State.ts b/src/mobx/State.ts index 02a60e7e..f7a99c96 100644 --- a/src/mobx/State.ts +++ b/src/mobx/State.ts @@ -164,6 +164,14 @@ export default class State { // Register events for notifications. client.addListener("message", this.notifications.onMessage); + client.addListener( + "message/mention", + this.notifications.onMessage, + ); + client.addListener( + "message/mention/everyone", + this.notifications.onMessage, + ); client.addListener( "user/relationship", this.notifications.onRelationship, @@ -268,6 +276,14 @@ export default class State { client.removeListener("message", this.queue.onMessage); client.removeListener("packet", this.onPacket); client.removeListener("message", this.notifications.onMessage); + client.removeListener( + "message/mention", + this.notifications.onMessage, + ); + client.removeListener( + "message/mention/everyone", + this.notifications.onMessage, + ); client.removeListener( "user/relationship", this.notifications.onRelationship, diff --git a/src/mobx/stores/NotificationOptions.ts b/src/mobx/stores/NotificationOptions.ts index 10e385eb..e10c7faa 100644 --- a/src/mobx/stores/NotificationOptions.ts +++ b/src/mobx/stores/NotificationOptions.ts @@ -157,7 +157,8 @@ export default class NotificationOptions } // Check channel notification settings - const mentioned = message.mention_ids?.includes(user._id); + const mentioned = message.mention_ids?.includes(user._id) || + (message as any).mentionsEveryone; switch (this.computeForChannel(message.channel!)) { case "muted": case "none":