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 channelMentions = allMentions.channels;
const isDMChannel = channelType === ChannelTypes.DM || channelType === ChannelTypes.DM_PERSONAL_NOTES;
if (isDMChannel) {
mentionsEveryone = false;
mentionsHere = false;
}
const shouldAddReferencedUser =
referencedMessage?.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);
});
});