This commit is contained in:
NanoAim
2025-07-05 12:59:15 +08:00
parent 6a98a1259a
commit 252d33f001
8 changed files with 56 additions and 10 deletions

2
external/lang vendored

View File

@@ -120,9 +120,10 @@ const Message = observer(
contrast={contrast} contrast={contrast}
sending={typeof queued !== "undefined"} sending={typeof queued !== "undefined"}
mention={ mention={
message.mention_ids && client.user client.user && (
? message.mention_ids.includes(client.user._id) (message.mention_ids?.includes(client.user._id)) ||
: undefined (message as any).mentionsEveryone
) || undefined
} }
failed={typeof queued?.error !== "undefined"} failed={typeof queued?.error !== "undefined"}
{...(attachContext {...(attachContext

View File

@@ -23,7 +23,7 @@ import { RenderAnchor } from "./plugins/anchors";
import { remarkChannels, RenderChannel } from "./plugins/channels"; import { remarkChannels, RenderChannel } from "./plugins/channels";
import { isOnlyEmoji, remarkEmoji, RenderEmoji } from "./plugins/emoji"; import { isOnlyEmoji, remarkEmoji, RenderEmoji } from "./plugins/emoji";
import { remarkHtmlToText } from "./plugins/htmlToText"; 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 { remarkSpoiler, RenderSpoiler } from "./plugins/spoiler";
import { remarkTimestamps } from "./plugins/timestamps"; import { remarkTimestamps } from "./plugins/timestamps";
import "./prism"; import "./prism";
@@ -39,6 +39,7 @@ const Null: React.FC = () => null;
const components = { const components = {
emoji: RenderEmoji, emoji: RenderEmoji,
mention: RenderMention, mention: RenderMention,
everyone: RenderEveryoneMention,
spoiler: RenderSpoiler, spoiler: RenderSpoiler,
channel: RenderChannel, channel: RenderChannel,
a: RenderAnchor, a: RenderAnchor,
@@ -143,6 +144,7 @@ const render = unified()
.use(remarkTimestamps) .use(remarkTimestamps)
.use(remarkEmoji) .use(remarkEmoji)
.use(remarkMention) .use(remarkMention)
.use(remarkEveryone)
.use(remarkHtmlToText) .use(remarkHtmlToText)
.use(remarkRehype, { .use(remarkRehype, {
handlers, handlers,

View File

@@ -2,6 +2,6 @@ import { passThroughComponents } from "./plugins/remarkRegexComponent";
import { timestampHandler } from "./plugins/timestamps"; import { timestampHandler } from "./plugins/timestamps";
export const handlers = { export const handlers = {
...passThroughComponents("emoji", "spoiler", "mention", "channel"), ...passThroughComponents("emoji", "spoiler", "mention", "channel", "everyone"),
timestamp: timestampHandler, timestamp: timestampHandler,
}; };

View File

@@ -1,6 +1,5 @@
import { RE_MENTIONS } from "revolt.js"; import { RE_MENTIONS, RE_EVERYONE } from "revolt.js";
import styled from "styled-components"; import styled from "styled-components";
import { clientController } from "../../../controllers/client/ClientController"; import { clientController } from "../../../controllers/client/ClientController";
import UserShort from "../../common/user/UserShort"; import UserShort from "../../common/user/UserShort";
import { createComponent, CustomComponentProps } from "./remarkRegexComponent"; 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 (
<EveryoneMention>
@everyone
</EveryoneMention>
);
}
export const remarkMention = createComponent("mention", RE_MENTIONS, (match) => export const remarkMention = createComponent("mention", RE_MENTIONS, (match) =>
clientController.getAvailableClient().users.has(match), clientController.getAvailableClient().users.has(match),
); );
export const remarkEveryone = createComponent("everyone", RE_EVERYONE, () => true);

View File

@@ -164,6 +164,14 @@ export default class State {
// Register events for notifications. // Register events for notifications.
client.addListener("message", this.notifications.onMessage); client.addListener("message", this.notifications.onMessage);
client.addListener(
"message/mention",
this.notifications.onMessage,
);
client.addListener(
"message/mention/everyone",
this.notifications.onMessage,
);
client.addListener( client.addListener(
"user/relationship", "user/relationship",
this.notifications.onRelationship, this.notifications.onRelationship,
@@ -268,6 +276,14 @@ export default class State {
client.removeListener("message", this.queue.onMessage); client.removeListener("message", this.queue.onMessage);
client.removeListener("packet", this.onPacket); client.removeListener("packet", this.onPacket);
client.removeListener("message", this.notifications.onMessage); client.removeListener("message", this.notifications.onMessage);
client.removeListener(
"message/mention",
this.notifications.onMessage,
);
client.removeListener(
"message/mention/everyone",
this.notifications.onMessage,
);
client.removeListener( client.removeListener(
"user/relationship", "user/relationship",
this.notifications.onRelationship, this.notifications.onRelationship,

View File

@@ -157,7 +157,8 @@ export default class NotificationOptions
} }
// Check channel notification settings // 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!)) { switch (this.computeForChannel(message.channel!)) {
case "muted": case "muted":
case "none": case "none":