fix(app): keep mention highlight when mentions are suppressed (#3242)

This commit is contained in:
Hampus
2026-10-06 20:58:28 +02:00
committed by GitHub
parent 8b6910d505
commit 6e28092cdc
2 changed files with 20 additions and 7 deletions
@@ -13,7 +13,6 @@ import {emojiEquals} from '@app/features/messaging/utils/ReactionUtils';
import Relationships from '@app/features/relationship/state/Relationships'; import Relationships from '@app/features/relationship/state/Relationships';
import * as ThemeUtils from '@app/features/theme/utils/ThemeUtils'; import * as ThemeUtils from '@app/features/theme/utils/ThemeUtils';
import {User} from '@app/features/user/models/User'; import {User} from '@app/features/user/models/User';
import UserGuildSettings from '@app/features/user/state/UserGuildSettings';
import Users from '@app/features/user/state/Users'; import Users from '@app/features/user/state/Users';
import {LRUMap} from '@app/lib/list/ListLruMap'; import {LRUMap} from '@app/lib/list/ListLruMap';
import {MessageFlags, MessageStates, MessageTypes} from '@fluxer/constants/src/ChannelConstants'; import {MessageFlags, MessageStates, MessageTypes} from '@fluxer/constants/src/ChannelConstants';
@@ -560,15 +559,23 @@ export class Message {
} }
} }
export const messageMentionsCurrentUser = (message: WireMessage): boolean => { interface MentionSuppression {
suppressEveryone?: boolean;
suppressRoles?: boolean;
}
export const messageMentionsCurrentUser = (
message: WireMessage,
{suppressEveryone = false, suppressRoles = false}: MentionSuppression = {},
): boolean => {
const channel = Channels.getChannel(message.channel_id); const channel = Channels.getChannel(message.channel_id);
if (!channel) return false; if (!channel) return false;
if (message.mention_everyone && !UserGuildSettings.isEveryoneMentionSuppressed(channel.guildId ?? null)) return true; if (message.mention_everyone && !suppressEveryone) return true;
if (message.mentions?.some((user) => user.id === Authentication.currentUserId)) { if (message.mentions?.some((user) => user.id === Authentication.currentUserId)) {
return true; return true;
} }
if (!channel.guildId) return false; if (!channel.guildId) return false;
if (UserGuildSettings.isRoleMentionSuppressed(channel.guildId)) return false; if (suppressRoles) return false;
const guild = Guilds.getGuild(channel.guildId); const guild = Guilds.getGuild(channel.guildId);
if (!guild) return false; if (!guild) return false;
const guildMember = GuildMembers.getMember(guild.id, Authentication.currentUserId); const guildMember = GuildMembers.getMember(guild.id, Authentication.currentUserId);
@@ -11,6 +11,7 @@ import {
} from '@app/features/notification/utils/MentionFeedFilters'; } from '@app/features/notification/utils/MentionFeedFilters';
import Relationships from '@app/features/relationship/state/Relationships'; import Relationships from '@app/features/relationship/state/Relationships';
import {makeSyncedField} from '@app/features/user/state/SyncedField'; import {makeSyncedField} from '@app/features/user/state/SyncedField';
import UserGuildSettings from '@app/features/user/state/UserGuildSettings';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants'; import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
import {MAX_MESSAGES_PER_CHANNEL} from '@fluxer/constants/src/LimitConstants'; import {MAX_MESSAGES_PER_CHANNEL} from '@fluxer/constants/src/LimitConstants';
import type {Channel as WireChannel} from '@fluxer/schema/src/domains/channel/ChannelSchemas'; import type {Channel as WireChannel} from '@fluxer/schema/src/domains/channel/ChannelSchemas';
@@ -179,14 +180,19 @@ class MentionFeed {
} }
handleMessageCreate(message: WireMessage): void { handleMessageCreate(message: WireMessage): void {
if (!messageMentionsCurrentUser(message)) { const channel = Channels.getChannel(message.channel_id);
if (!channel) return;
const guildId = channel.guildId ?? null;
const mentioned = messageMentionsCurrentUser(message, {
suppressEveryone: UserGuildSettings.isEveryoneMentionSuppressed(guildId),
suppressRoles: UserGuildSettings.isRoleMentionSuppressed(guildId),
});
if (!mentioned) {
return; return;
} }
if (Relationships.isBlocked(message.author.id)) { if (Relationships.isBlocked(message.author.id)) {
return; return;
} }
const channel = Channels.getChannel(message.channel_id);
if (!channel) return;
if (!this.isMessageIncludedByFilters(message, channel)) { if (!this.isMessageIncludedByFilters(message, channel)) {
return; return;
} }