226 lines
11 KiB
TypeScript
226 lines
11 KiB
TypeScript
// Metro module 14973 (f14974).
|
|
import { useMemo, useEffect } from "react";
|
|
import { View } from "react-native";
|
|
import JoinedThreadsStore from "../../threads/JoinedThreadsStore";
|
|
import { isThread } from "../../../records/ChannelRecord";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import GuildChannelStore from "../../../stores/GuildChannelStore";
|
|
import GuildReadStateStore from "../../../stores/GuildReadStateStore";
|
|
import GuildStore from "../../../stores/GuildStore";
|
|
import ReadStateStore from "../../../stores/ReadStateStore";
|
|
import RelationshipStore from "../../../stores/RelationshipStore";
|
|
import UserGuildSettingsStore from "../../../stores/UserGuildSettingsStore";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import { EMPTY_STRING_SNOWFLAKE_ID, NOOP } from "../../../Constants";
|
|
import { UnreadSetting } from "../../read_states/ReadStateConstants";
|
|
import { jsx } from "react/jsx-runtime";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import { useStateFromStores, useStateFromStoresObject } from "../../../_bundle/Module589";
|
|
import { MobileHomeDrawerExperiment } from "./HomeDrawerExperiment";
|
|
import useChatLayout from "../../chat/native/useChatLayout";
|
|
import { BellZIcon } from "../../../design/components/Icon/native/redesign/generated/BellZIcon";
|
|
import { BellSlashIcon } from "../../../design/components/Icon/native/redesign/generated/BellSlashIcon";
|
|
import { Text } from "../../../design/components/Text/native/Text";
|
|
import { useIsHomeDrawerChannelMuted } from "./isHomeDrawerChannelMuted";
|
|
import { useIsHomeDrawerChannelInChannelList } from "./isHomeDrawerChannelInChannelList";
|
|
import { computeChannelName } from "../../channel/useChannelName";
|
|
import SnowflakeUtils from "../../../utils/SnowflakeUtils";
|
|
import { useVoiceUsers, GuildVoiceState } from "./HomeDrawerGuildVoiceState";
|
|
import { useHomeDrawerGuildTyping } from "./useHomeDrawerGuildTyping";
|
|
import useTypingText from "../../chat/useTypingText";
|
|
import StreamingSubtitle from "./subtitles/StreamingSubtitle";
|
|
import VoiceSubtitle from "./subtitles/VoiceSubtitle";
|
|
import MentionSubtitle from "./subtitles/MentionSubtitle";
|
|
import TypingSubtitle from "./subtitles/TypingSubtitle";
|
|
import UnreadSubtitle from "./subtitles/UnreadSubtitle";
|
|
import { HomeDrawerSharedItem } from "./HomeDrawerShared";
|
|
let c10595_20, useStyles;
|
|
const GuildRowWrapper = function GuildRowWrapper(props) {
|
|
let stateFromStores2, memo, isHomeDrawerChannelMuted, isHomeDrawerChannelInChannelList, unreadChannel, unreadChannelName, unreadChannelCount, mentionChannel, mentionChannelName, mentionChannelCount, voiceUsers, streamingUser, typingChannelId, typingChannelName, stateFromStores3, text, c21495_21, memo2;
|
|
const { guild, disableSubtitle, onActiveHookChange } = props;
|
|
stateFromStores2 = void 0;
|
|
memo = void 0;
|
|
isHomeDrawerChannelMuted = void 0;
|
|
isHomeDrawerChannelInChannelList = void 0;
|
|
unreadChannel = void 0;
|
|
unreadChannelName = void 0;
|
|
unreadChannelCount = void 0;
|
|
mentionChannel = void 0;
|
|
mentionChannelName = void 0;
|
|
mentionChannelCount = void 0;
|
|
voiceUsers = void 0;
|
|
streamingUser = void 0;
|
|
typingChannelId = void 0;
|
|
typingChannelName = void 0;
|
|
stateFromStores3 = void 0;
|
|
text = void 0;
|
|
c21495_21 = void 0;
|
|
memo2 = void 0;
|
|
const styles = useStyles();
|
|
const stateFromStores = useStateFromStores([GuildReadStateStore], () => GuildReadStateStore.hasUnread(guild.id));
|
|
stateFromStores2 = useStateFromStores([UserGuildSettingsStore], () => UserGuildSettingsStore.getMuteConfig(guild.id));
|
|
memo = useMemo(() => stateFromStores2 == null ? {
|
|
isMuted: false,
|
|
isTemporary: false
|
|
} : {
|
|
isMuted: stateFromStores2.end_time == null || new Date(stateFromStores2.end_time) > new Date(),
|
|
isTemporary: stateFromStores2.end_time != null
|
|
}, [stateFromStores2]);
|
|
const memo3 = useMemo(() => <View style={styles.guildName}>
|
|
<Text variant="text-md/medium" style={styles.guildNameText} lineClamp={1} color={memo.isMuted ? "text-muted" : "text-default"}>{guild.name}</Text>
|
|
{jsx(memo.isMuted ? memo.isTemporary ? BellZIcon : BellSlashIcon : NOOP, {
|
|
size: "xs",
|
|
color: "icon-muted"
|
|
})}
|
|
</View>, [guild, memo, styles.guildName, styles.guildNameText]);
|
|
isHomeDrawerChannelMuted = useIsHomeDrawerChannelMuted();
|
|
isHomeDrawerChannelInChannelList = useIsHomeDrawerChannelInChannelList();
|
|
const stateFromStoresObject = useStateFromStoresObject([GuildChannelStore, ChannelStore, UserStore, RelationshipStore, ReadStateStore, UserGuildSettingsStore, JoinedThreadsStore], () => {
|
|
const r15 = GuildChannelStore.getSelectableChannelIds(guild.id).filter((item) => {
|
|
const basicChannel = ChannelStore.getBasicChannel(item);
|
|
let r11 = basicChannel != null;
|
|
if (r11) {
|
|
const isHomeDrawerChannelMuted3 = isHomeDrawerChannelMuted(basicChannel);
|
|
let r14 = !isHomeDrawerChannelMuted3;
|
|
if (!isHomeDrawerChannelMuted3) {
|
|
const r16 = isThread(basicChannel.type) && !JoinedThreadsStore.hasJoined(item);
|
|
r14 = r16 ? !r16 : !!isHomeDrawerChannelInChannelList(basicChannel) && (ReadStateStore.hasUnread(item) && UserGuildSettingsStore.resolveUnreadSetting(basicChannel) === UnreadSetting.ALL_MESSAGES);
|
|
}
|
|
r11 = r14;
|
|
}
|
|
return r11;
|
|
});
|
|
const unreadChannel2 = r15.length > 0 ? ChannelStore.getChannel(r15[0]) : void 0;
|
|
return {
|
|
unreadChannel: unreadChannel2,
|
|
unreadChannelName: unreadChannel2 != null ? computeChannelName(unreadChannel2, UserStore, RelationshipStore) : void 0,
|
|
unreadChannelCount: r15.length
|
|
};
|
|
}, [guild.id, isHomeDrawerChannelMuted, isHomeDrawerChannelInChannelList]);
|
|
unreadChannel = stateFromStoresObject.unreadChannel;
|
|
unreadChannelName = stateFromStoresObject.unreadChannelName;
|
|
unreadChannelCount = stateFromStoresObject.unreadChannelCount;
|
|
const stateFromStoresObject2 = useStateFromStoresObject([GuildReadStateStore, ChannelStore, UserStore, RelationshipStore, JoinedThreadsStore], () => {
|
|
const r16 = GuildReadStateStore.getMutableGuildStates()[guild.id];
|
|
let c27879_0 = r16;
|
|
if (r16 == null) {
|
|
return {
|
|
mentionChannel: void 0,
|
|
mentionChannelName: void 0,
|
|
mentionChannelCount: 0
|
|
};
|
|
}
|
|
const r24 = SnowflakeUtils.keys(r16.mentionCounts).filter((item) => {
|
|
if (c27879_0.mentionCounts[item].count <= 0) {
|
|
return false;
|
|
}
|
|
const basicChannel = ChannelStore.getBasicChannel(item);
|
|
let r14 = basicChannel != null;
|
|
if (r14) {
|
|
const r17 = isThread(basicChannel.type) && !JoinedThreadsStore.hasJoined(item);
|
|
r14 = r17 ? !r17 : isHomeDrawerChannelInChannelList(basicChannel);
|
|
}
|
|
return r14;
|
|
});
|
|
const mentionChannel2 = r24.length > 0 ? ChannelStore.getChannel(r24[0]) : void 0;
|
|
return {
|
|
mentionChannel: mentionChannel2,
|
|
mentionChannelName: mentionChannel2 != null ? computeChannelName(mentionChannel2, UserStore, RelationshipStore) : void 0,
|
|
mentionChannelCount: r24.length
|
|
};
|
|
}, [guild.id, isHomeDrawerChannelInChannelList]);
|
|
mentionChannel = stateFromStoresObject2.mentionChannel;
|
|
mentionChannelName = stateFromStoresObject2.mentionChannelName;
|
|
mentionChannelCount = stateFromStoresObject2.mentionChannelCount;
|
|
const voiceUsers2 = useVoiceUsers(guild);
|
|
voiceUsers = voiceUsers2.voiceUsers;
|
|
streamingUser = voiceUsers2.streamingUser;
|
|
const streamingChannelId = voiceUsers2.streamingChannelId;
|
|
const homeDrawerGuildTyping = useHomeDrawerGuildTyping(guild.id);
|
|
typingChannelId = homeDrawerGuildTyping.typingChannelId;
|
|
typingChannelName = homeDrawerGuildTyping.typingChannelName;
|
|
const typingUserIds = homeDrawerGuildTyping.typingUserIds;
|
|
stateFromStores3 = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(typingChannelId), [typingChannelId]);
|
|
text = useTypingText({
|
|
channelId: typingChannelId == null ? EMPTY_STRING_SNOWFLAKE_ID : typingChannelId,
|
|
guildId: guild.id,
|
|
typingUserIds
|
|
});
|
|
const r3 = !(memo.isMuted || disableSubtitle || voiceUsers.length === 0);
|
|
c21495_21 = r3;
|
|
memo2 = useMemo(() => {
|
|
let r15;
|
|
L23: {
|
|
if (c21495_21) {
|
|
r15 = streamingUser != null ? c10595_20.STREAMING : c10595_20.VOICE;
|
|
} else if (disableSubtitle) {
|
|
r15 = c10595_20.NONE;
|
|
} else {
|
|
if (mentionChannelName != null && mentionChannelCount > 0) {
|
|
r15 = c10595_20.MENTION;
|
|
break L23;
|
|
}
|
|
if (typingChannelId != null && text != null && !memo.isMuted) {
|
|
r15 = c10595_20.TYPING;
|
|
break L23;
|
|
}
|
|
r15 = stateFromStores && (unreadChannelName != null && unreadChannelCount > 0) ? c10595_20.UNREAD : c10595_20.NONE;
|
|
}
|
|
}
|
|
return r15;
|
|
}, [r3, streamingUser, disableSubtitle, mentionChannelName, mentionChannelCount, typingChannelId, text, memo.isMuted, stateFromStores, unreadChannelName, unreadChannelCount]);
|
|
useEffect(() => {
|
|
if (onActiveHookChange != null) {
|
|
onActiveHookChange(memo2);
|
|
}
|
|
}, [memo2, onActiveHookChange]);
|
|
return <HomeDrawerSharedItem title={memo3} subtitle={useMemo(() => {
|
|
if (c10595_20.STREAMING === memo2) {
|
|
return <StreamingSubtitle guildId={guild.id} streamingUser={streamingUser} />;
|
|
}
|
|
if (c10595_20.VOICE === memo2) {
|
|
return <VoiceSubtitle guildId={guild.id} voiceUsers={voiceUsers} />;
|
|
}
|
|
if (c10595_20.MENTION === memo2) {
|
|
return mentionChannelName != null ? <MentionSubtitle guild={guild} channel={mentionChannel} channelName={mentionChannelName} count={mentionChannelCount} /> : null;
|
|
}
|
|
if (c10595_20.TYPING === memo2) {
|
|
return <TypingSubtitle guild={guild} channel={stateFromStores3} channelName={typingChannelName} text={text} />;
|
|
}
|
|
if (c10595_20.UNREAD === memo2) {
|
|
return unreadChannelName != null ? <UnreadSubtitle guild={guild} channel={unreadChannel} channelName={unreadChannelName} count={unreadChannelCount} /> : null;
|
|
}
|
|
if (c10595_20.NONE === memo2) {
|
|
return null;
|
|
}
|
|
}, [memo2, guild, streamingUser, voiceUsers, mentionChannel, mentionChannelName, mentionChannelCount, stateFromStores3, typingChannelName, text, unreadChannel, unreadChannelName, unreadChannelCount])} right={memo.isMuted ? null : disableSubtitle ? null : voiceUsers.length !== 0 ? <GuildVoiceState voiceUsers={voiceUsers} streamingChannelId={streamingChannelId} streamingUser={streamingUser} guildId={guild.id} /> : null} />;
|
|
};
|
|
c10595_20 = {
|
|
STREAMING: "streaming",
|
|
VOICE: "voice",
|
|
MENTION: "mention",
|
|
TYPING: "typing",
|
|
UNREAD: "unread",
|
|
NONE: "none"
|
|
};
|
|
useStyles = createStyles({
|
|
guildName: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: 4
|
|
},
|
|
guildNameText: {
|
|
flexShrink: 1
|
|
}
|
|
});
|
|
export default function HomeDrawerGuildRow(props) {
|
|
const { guildId, disableSubtitle: disableSubtitle2, onActiveHookChange: onActiveHookChange2 } = props;
|
|
const stateFromStores4 = useStateFromStores([GuildStore], () => GuildStore.getGuild(guildId));
|
|
const enableHome = MobileHomeDrawerExperiment.useConfig({
|
|
location: "guild-row"
|
|
}).enableHome;
|
|
const isChatBesideChannelList = useChatLayout().isChatBesideChannelList;
|
|
return stateFromStores4 == null ? null : enableHome ? isChatBesideChannelList ? null : <GuildRowWrapper guild={stateFromStores4} disableSubtitle={disableSubtitle2} onActiveHookChange={onActiveHookChange2} /> : null;
|
|
};
|
|
export { c10595_20 as HomeDrawerActiveHook };
|