fix(mentions): ignore @everyone and @here in one-to-one DMs (#3199)

This commit is contained in:
Hampus
2026-10-04 16:59:04 +02:00
committed by GitHub
parent 0aeff01c2d
commit 5ca458dada
4 changed files with 51 additions and 3 deletions
@@ -90,6 +90,10 @@ export class MessageMentionService {
const roleMentions = allMentions.roles; const roleMentions = allMentions.roles;
const channelMentions = allMentions.channels; const channelMentions = allMentions.channels;
const isDMChannel = channelType === ChannelTypes.DM || channelType === ChannelTypes.DM_PERSONAL_NOTES; const isDMChannel = channelType === ChannelTypes.DM || channelType === ChannelTypes.DM_PERSONAL_NOTES;
if (isDMChannel) {
mentionsEveryone = false;
mentionsHere = false;
}
const shouldAddReferencedUser = const shouldAddReferencedUser =
referencedMessage?.authorId && referencedMessage?.authorId &&
referencedMessage.authorId !== message.authorId && referencedMessage.authorId !== message.authorId &&
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {createTestAccount} from '@app/api/auth/tests/AuthTestUtils';
import {
createDmChannel,
createFriendship,
createGroupDmChannel,
sendChannelMessage,
} from '@app/api/channel/tests/ChannelTestUtils';
import {type ApiTestHarness, createApiTestHarness} from '@app/api/test/ApiTestHarness';
import {afterAll, beforeAll, beforeEach, describe, expect, it} from 'vitest';
describe('DM everyone mention', () => {
let harness: ApiTestHarness;
beforeAll(async () => {
harness = await createApiTestHarness();
});
beforeEach(async () => {
await harness.reset();
});
afterAll(async () => {
await harness?.shutdown();
});
it('does not mention everyone in a one-to-one DM', async () => {
const user1 = await createTestAccount(harness);
const user2 = await createTestAccount(harness);
await createFriendship(harness, user1, user2);
const dm = await createDmChannel(harness, user1.token, user2.userId);
const everyone = await sendChannelMessage(harness, user1.token, dm.id, '@everyone test');
const here = await sendChannelMessage(harness, user1.token, dm.id, '@here test');
expect(everyone.mention_everyone).toBe(false);
expect(here.mention_everyone).toBe(false);
});
it('still mentions everyone in a group DM', async () => {
const user1 = await createTestAccount(harness);
const user2 = await createTestAccount(harness);
const user3 = await createTestAccount(harness);
await createFriendship(harness, user1, user2);
await createFriendship(harness, user1, user3);
const groupDm = await createGroupDmChannel(harness, user1.token, [user2.userId, user3.userId]);
const message = await sendChannelMessage(harness, user1.token, groupDm.id, '@everyone test');
expect(message.mention_everyone).toBe(true);
});
});
@@ -26,7 +26,7 @@ export function createSpecialMentionPayload(kind: SpecialMentionKind): ComposerI
} }
export function areSpecialMentionsAllowed( export function areSpecialMentionsAllowed(
channel: Pick<Channel, 'guildId' | 'isPersonalNotes'> | null, channel: Pick<Channel, 'guildId' | 'isGroupDM'> | null,
allowSpecialMentions: boolean | undefined, allowSpecialMentions: boolean | undefined,
allowedTriggers: ReadonlyArray<TriggerType> | undefined, allowedTriggers: ReadonlyArray<TriggerType> | undefined,
canMentionEveryone: boolean, canMentionEveryone: boolean,
@@ -34,7 +34,7 @@ export function areSpecialMentionsAllowed(
if (channel == null || allowSpecialMentions === false || !isAutocompleteTriggerAllowed('mention', allowedTriggers)) { if (channel == null || allowSpecialMentions === false || !isAutocompleteTriggerAllowed('mention', allowedTriggers)) {
return false; return false;
} }
return channel.guildId == null ? !channel.isPersonalNotes() : canMentionEveryone; return channel.guildId == null ? channel.isGroupDM() : canMentionEveryone;
} }
export function hasOpenCodeFence(text: string): boolean { export function hasOpenCodeFence(text: string): boolean {
@@ -17,7 +17,7 @@ export function isMentioned(user: User, message: Message): boolean {
return false; return false;
} }
const suppressEveryone = UserGuildSettings.isEveryoneMentionSuppressed(channel.guildId ?? null); const suppressEveryone = UserGuildSettings.isEveryoneMentionSuppressed(channel.guildId ?? null);
const mentionEveryone = message.mentionEveryone && !suppressEveryone; const mentionEveryone = message.mentionEveryone && !channel.isDM() && !suppressEveryone;
if (mentionEveryone) { if (mentionEveryone) {
return true; return true;
} }