mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
refactor(app): name mute and unread state accessors by intent (#1859)
This commit is contained in:
1 parent
52781cfa2d
commit
a2099fb0e2
33 files changed
+173
-490
No files matched your search
@@ -75,8 +75,8 @@ const setBadge = (badge: number): void => {
|
||||
export const AppBadge: React.FC = observer(() => {
|
||||
const relationships = Relationships.getRelationships();
|
||||
const unreadMessageBadgeEnabled = Notification.unreadMessageBadgeEnabled;
|
||||
const mentionCount = GuildReadState.getTotalMentionCount();
|
||||
const hasUnread = GuildReadState.hasAnyUnread;
|
||||
const mentionCount = GuildReadState.mentionCountAcrossGuilds();
|
||||
const hasUnread = GuildReadState.anyGuildUnread;
|
||||
const pendingCount = RuntimeConfig.directMessagesDisabled
|
||||
? 0
|
||||
: relationships.filter((relationship) => relationship.type === RelationshipTypes.INCOMING_REQUEST).length;
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ export const FavoritesGuildHeaderBottomSheet: React.FC<FavoritesGuildHeaderBotto
|
||||
({isOpen, onClose}) => {
|
||||
const {i18n} = useLingui();
|
||||
const hideMutedChannels = Favorites.hideMutedChannels;
|
||||
const settings = UserGuildSettings.getSettings(FAVORITES_GUILD_ID);
|
||||
const settings = UserGuildSettings.getSettingsForScope(FAVORITES_GUILD_ID);
|
||||
const isMuted = settings?.muted ?? false;
|
||||
const handleAddChannel = () => {
|
||||
ModalCommands.pushAfterBottomSheetClose(
|
||||
|
||||
@@ -360,7 +360,7 @@ const UnreadChannelCard = observer(function UnreadChannelCard({
|
||||
const messageGroupSpacing = Accessibility.getMessageGroupSpacingValue(messageDisplayCompact);
|
||||
const mentionCount = ReadStates.getMentionCount(channel.id);
|
||||
const isCollapsed = UnreadChannels.isCollapsed(channel.id);
|
||||
const isMuted = UserGuildSettings.isGuildOrCategoryOrChannelMuted(channel.guildId ?? null, channel.id);
|
||||
const isMuted = UserGuildSettings.isMutedAtAnyLevel(channel.guildId ?? null, channel.id);
|
||||
const previewMessages = previewData?.messages ?? [];
|
||||
const oldestUnreadMessageId = previewData?.oldestUnreadMessageId ?? null;
|
||||
const totalUnreadCount = ReadStates.getUnreadCount(channel.id);
|
||||
|
||||
@@ -238,7 +238,7 @@ export const ChannelItem = observer(
|
||||
const canInvite = InviteUtils.canInviteToChannel(channel.id, channel.guildId);
|
||||
const mobileLayout = MobileLayout;
|
||||
const isMuted = UserGuildSettings.isGuildOrChannelMuted(guild.id, channel.id);
|
||||
const isChannelDirectlyMuted = UserGuildSettings.isChannelMuted(guild.id, channel.id);
|
||||
const isChannelDirectlyMuted = UserGuildSettings.isChannelDirectlyMuted(guild.id, channel.id);
|
||||
const currentUserCount =
|
||||
channelIsVoice && channel.userLimit != null && channel.userLimit > 0
|
||||
? Object.keys(MediaEngine.getAllVoiceStatesInChannel(guild.id, channel.id)).length
|
||||
|
||||
@@ -164,7 +164,7 @@ export const ChannelListContent = observer(({guild, scrollY}: {guild: Guild; scr
|
||||
const {i18n} = useLingui();
|
||||
const channels = Channels.getGuildChannels(guild.id);
|
||||
const location = useLocation();
|
||||
const userGuildSettings = UserGuildSettings.getSettings(guild.id);
|
||||
const userGuildSettings = UserGuildSettings.getSettingsForScope(guild.id);
|
||||
const isDraggingAnything = useDragLayer((monitor) => {
|
||||
if (!monitor.isDragging()) return false;
|
||||
const itemType = monitor.getItemType();
|
||||
@@ -337,7 +337,7 @@ export const ChannelListContent = observer(({guild, scrollY}: {guild: Guild; scr
|
||||
const unreadCount = ReadStates.getUnreadCount(channelId);
|
||||
const mentionCount = ReadStates.getMentionCount(channelId);
|
||||
const isMuted =
|
||||
UserGuildSettings.isCategoryMuted(guild.id, channelId) || UserGuildSettings.isChannelMuted(guild.id, channelId);
|
||||
UserGuildSettings.isParentCategoryMuted(guild.id, channelId) || UserGuildSettings.isChannelDirectlyMuted(guild.id, channelId);
|
||||
const channel = Channels.getChannel(channelId);
|
||||
const unreadBadgesLevel = channel
|
||||
? UserGuildSettings.resolvedUnreadBadgesLevel({
|
||||
@@ -360,13 +360,13 @@ export const ChannelListContent = observer(({guild, scrollY}: {guild: Guild; scr
|
||||
for (const group of channelGroups) {
|
||||
const isCollapsed = group.category ? (collapsedCategories?.has(group.category.id) ?? false) : false;
|
||||
const isNullSpace = !group.category;
|
||||
const isCategoryMuted = group.category ? UserGuildSettings.isChannelMuted(guild.id, group.category.id) : false;
|
||||
const isCategoryMuted = group.category ? UserGuildSettings.isChannelDirectlyMuted(guild.id, group.category.id) : false;
|
||||
let filteredTextChannels: Array<Channel>;
|
||||
let filteredVoiceChannels: Array<Channel>;
|
||||
if (hideMutedChannels) {
|
||||
filteredTextChannels = [];
|
||||
for (const ch of group.textChannels) {
|
||||
const isMuted = UserGuildSettings.isChannelMuted(guild.id, ch.id);
|
||||
const isMuted = UserGuildSettings.isChannelDirectlyMuted(guild.id, ch.id);
|
||||
if (
|
||||
shouldShowChannelWhenHidingMutedChannels({
|
||||
isMuted,
|
||||
@@ -380,7 +380,7 @@ export const ChannelListContent = observer(({guild, scrollY}: {guild: Guild; scr
|
||||
}
|
||||
filteredVoiceChannels = [];
|
||||
for (const ch of group.voiceChannels) {
|
||||
const isMuted = UserGuildSettings.isChannelMuted(guild.id, ch.id);
|
||||
const isMuted = UserGuildSettings.isChannelDirectlyMuted(guild.id, ch.id);
|
||||
if (
|
||||
shouldShowChannelWhenHidingMutedChannels({
|
||||
isMuted,
|
||||
|
||||
@@ -206,11 +206,11 @@ const FavoriteChannelResolvedItem = observer(
|
||||
const channelDisplayName = channel.isPrivate() ? ChannelUtils.getDMDisplayName(channel) : channel.name;
|
||||
const displayName = favoriteChannel.nickname || channelDisplayName || i18n._(UNKNOWN_CHANNEL_DESCRIPTOR);
|
||||
const isChannelDirectlyMuted = channel.guildId
|
||||
? UserGuildSettings.isChannelMuted(channel.guildId, channel.id)
|
||||
? UserGuildSettings.isChannelDirectlyMuted(channel.guildId, channel.id)
|
||||
: false;
|
||||
const isMuted =
|
||||
isChannelDirectlyMuted ||
|
||||
(channel.guildId ? UserGuildSettings.isCategoryMuted(channel.guildId, channel.id) : false);
|
||||
(channel.guildId ? UserGuildSettings.isParentCategoryMuted(channel.guildId, channel.id) : false);
|
||||
const unreadBadgesLevel = channel.guildId
|
||||
? UserGuildSettings.resolvedUnreadBadgesLevel({
|
||||
id: channel.id,
|
||||
|
||||
@@ -665,7 +665,7 @@ function getDMScrollIndicatorSeverity(channelId: string): ScrollIndicatorSeverit
|
||||
const unreadState = getChannelUnreadState({
|
||||
unreadCount: ReadStates.getPrivateChannelUnreadCount(channelId),
|
||||
mentionCount,
|
||||
isMuted: UserGuildSettings.isChannelMuted(null, channelId),
|
||||
isMuted: UserGuildSettings.isChannelDirectlyMuted(null, channelId),
|
||||
showFadedUnreadOnMutedChannels: Accessibility.showFadedUnreadOnMutedChannels,
|
||||
});
|
||||
if (mentionCount > 0) return 'mention';
|
||||
@@ -674,8 +674,8 @@ function getDMScrollIndicatorSeverity(channelId: string): ScrollIndicatorSeverit
|
||||
}
|
||||
|
||||
function getGuildScrollIndicatorSeverity(guildId: string): ScrollIndicatorSeverity | null {
|
||||
if (GuildReadState.getMentionCount(guildId) > 0) return 'mention';
|
||||
if (GuildReadState.hasUnread(guildId)) return 'unread';
|
||||
if (GuildReadState.mentionCountForGuild(guildId) > 0) return 'mention';
|
||||
if (GuildReadState.guildIsUnread(guildId)) return 'unread';
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1327,10 +1327,10 @@ const GUILD_RAIL_INDICATORS_BY_TOKEN: Record<string, SkeletonGuildRailItemIndica
|
||||
function resolveGuildRailIndicator(guildIds: ReadonlyArray<string>): SkeletonGuildRailItemIndicator {
|
||||
let hasUnread = false;
|
||||
for (const guildId of guildIds) {
|
||||
if (GuildReadState.getMentionCount(guildId) > 0) {
|
||||
if (GuildReadState.mentionCountForGuild(guildId) > 0) {
|
||||
return SkeletonGuildRailItemIndicator.MENTION;
|
||||
}
|
||||
if (GuildReadState.hasUnread(guildId)) {
|
||||
if (GuildReadState.guildIsUnread(guildId)) {
|
||||
hasUnread = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,8 +316,8 @@ export const GuildFolderItem = observer((props: GuildFolderItemProps) => {
|
||||
}) as CSSProperties,
|
||||
[folderColor],
|
||||
);
|
||||
const hasUnreadMessages = guilds.some((guild) => GuildReadState.hasUnread(guild.id));
|
||||
const totalMentionCount = guilds.reduce((sum, guild) => sum + GuildReadState.getMentionCount(guild.id), 0);
|
||||
const hasUnreadMessages = guilds.some((guild) => GuildReadState.guildIsUnread(guild.id));
|
||||
const totalMentionCount = guilds.reduce((sum, guild) => sum + GuildReadState.mentionCountForGuild(guild.id), 0);
|
||||
let folderScrollTargetRef: React.RefCallback<HTMLElement> | null = null;
|
||||
if (registerScrollTarget != null) {
|
||||
folderScrollTargetRef = registerScrollTarget(folderId);
|
||||
|
||||
@@ -72,7 +72,7 @@ export function resolveDMListItemUnreadState(channelId: string): ChannelUnreadSt
|
||||
return getChannelUnreadState({
|
||||
unreadCount: ReadStates.getUnreadCount(channelId),
|
||||
mentionCount: ReadStates.getMentionCount(channelId),
|
||||
isMuted: UserGuildSettings.isChannelMuted(null, channelId),
|
||||
isMuted: UserGuildSettings.isChannelDirectlyMuted(null, channelId),
|
||||
showFadedUnreadOnMutedChannels: Accessibility.showFadedUnreadOnMutedChannels,
|
||||
unreadBadgesLevel: null,
|
||||
});
|
||||
@@ -124,7 +124,7 @@ const ResolvedDMListItem = observer(function ResolvedDMListItem({
|
||||
const contextMenuOpen = useContextMenuHoverState(buttonRef, !isMobileExperience);
|
||||
const [isFocused, setIsFocused] = useState(false);
|
||||
const {keyboardModeEnabled} = KeyboardMode;
|
||||
const isMuted = UserGuildSettings.isChannelMuted(null, channel.id);
|
||||
const isMuted = UserGuildSettings.isChannelDirectlyMuted(null, channel.id);
|
||||
const mentionCount = ReadStates.getMentionCount(channel.id);
|
||||
const unreadState = resolveDMListItemUnreadState(channel.id);
|
||||
const directMessageName = recipient ? NicknameUtils.getNickname(recipient, null, channel.id) : null;
|
||||
|
||||
@@ -107,9 +107,9 @@ export function useGuildListItemState({
|
||||
isSelected,
|
||||
selectedGuildIndex,
|
||||
}: UseGuildListItemStateOptions): GuildListItemState {
|
||||
const hasUnreadMessages = GuildReadState.hasUnread(guild.id);
|
||||
const mentionCount = GuildReadState.getMentionCount(guild.id);
|
||||
const settings = UserGuildSettings.getSettings(guild.id);
|
||||
const hasUnreadMessages = GuildReadState.guildIsUnread(guild.id);
|
||||
const mentionCount = GuildReadState.mentionCountForGuild(guild.id);
|
||||
const settings = UserGuildSettings.getSettingsForScope(guild.id);
|
||||
const isMuted = settings.muted;
|
||||
const muteConfig = settings.mute_config;
|
||||
let muteEndTime: string | null = null;
|
||||
|
||||
Reference in new issue
Block a user