211 lines
8.3 KiB
TypeScript
211 lines
8.3 KiB
TypeScript
// Metro module 15795 (f15796).
|
|
import { memo, useCallback, useRef, useEffect } from "react";
|
|
import { Pressable, View } from "react-native";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import ReadStateStore from "../../../stores/ReadStateStore";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import { ChannelTypes } from "../../../Constants";
|
|
import { createStyles } from "../../../design/components/Styles/native/createStyles";
|
|
import Module712 from "../../../_bundle/Module712";
|
|
import { transitionToGuild } from "../../routing/transitionToGuild.native";
|
|
import SimpleGuild from "./shared/SimpleGuild";
|
|
import { useStateFromStores } from "../../../_bundle/Module589";
|
|
import { Avatar, AvatarSizes } from "../../../design/void/native";
|
|
import GroupDMAvatar from "../../group_dm/native/GroupDMAvatar";
|
|
import FastImage from "../../../components_native/common/FastImage";
|
|
import { getChannelIconSource } from "../../channel/getChannelIcon";
|
|
import ChannelActionCreators from "../../../actions/ChannelActionCreators";
|
|
import { transitionToChannel } from "../../routing/transitionToChannel";
|
|
import MaskedBadge from "../../main_tabs_v2/native/shared_components/MaskedBadge";
|
|
import { useCategoryStyles, renderCategoryItem } from "../../channel_list_v2/native/items/RedesignCategory";
|
|
import MobileVisualRefreshExperiment from "../../themes/experiments/MobileVisualRefreshExperiment";
|
|
import useWindowDimensions_native from "../../screen/useWindowDimensions.native";
|
|
import isGuildSelectable from "./isGuildSelectable";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { AnimatedFastList } from "../../../lib/native/FastList";
|
|
let useStyles, GuildItemInner, PrivateChannelItemInner, renderHistorySection;
|
|
const HistorySeparator = function HistorySeparator() {
|
|
const styles = useStyles();
|
|
return <View style={styles.guildHistorySeparatorWrapper}>
|
|
<View style={styles.guildHistorySeparator} />
|
|
</View>;
|
|
};
|
|
renderHistorySection = function renderHistorySection() {
|
|
return <HistorySeparator />;
|
|
};
|
|
useStyles = createStyles({
|
|
listWrapper: {
|
|
marginTop: 8
|
|
},
|
|
list: {
|
|
marginBottom: 4,
|
|
flexShrink: 0
|
|
},
|
|
maskStrokeStyle: {
|
|
backgroundColor: Module712.colors.BACKGROUND_BASE_LOW
|
|
},
|
|
privateChannelWrapper: {
|
|
position: "relative",
|
|
paddingVertical: 2,
|
|
justifyContent: "center",
|
|
alignItems: "center"
|
|
},
|
|
privateChannelIcon: {
|
|
width: 48,
|
|
height: 48,
|
|
borderRadius: 24,
|
|
overflow: "hidden"
|
|
},
|
|
badgeWrapper: {
|
|
position: "absolute",
|
|
top: "50%",
|
|
left: "50%",
|
|
marginLeft: 6,
|
|
marginTop: 6
|
|
},
|
|
guildWrapper: {
|
|
paddingVertical: 2,
|
|
justifyContent: "center",
|
|
alignItems: "center"
|
|
},
|
|
guildHistorySeparatorWrapper: {
|
|
flex: 1,
|
|
justifyContent: "center",
|
|
alignItems: "center"
|
|
},
|
|
guildHistorySeparator: {
|
|
width: 2,
|
|
height: 32,
|
|
borderRadius: Module712.radii.round,
|
|
backgroundColor: Module712.colors.BACKGROUND_MOD_STRONG
|
|
}
|
|
});
|
|
GuildItemInner = memo(function GuildItemInner(props) {
|
|
const { guildId, selected, onGuildSelect } = props;
|
|
const styles = useStyles();
|
|
return <View style={styles.guildWrapper}>
|
|
<SimpleGuild size={48} borderRadius={16} guildId={guildId} selected={selected} onPress={useCallback(() => {
|
|
onGuildSelect(guildId);
|
|
}, [guildId, onGuildSelect])} onLongPress={useCallback(() => {
|
|
transitionToGuild(guildId);
|
|
}, [guildId])} backgroundColor={styles.maskStrokeStyle.backgroundColor} />
|
|
</View>;
|
|
});
|
|
PrivateChannelItemInner = memo(function PrivateChannelItemInner(props) {
|
|
let stateFromStores2;
|
|
const channelId = props.channelId;
|
|
stateFromStores2 = void 0;
|
|
const styles = useStyles();
|
|
const stateFromStores = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(channelId));
|
|
stateFromStores2 = useStateFromStores([UserStore], () => (stateFromStores == null ? void 0 : stateFromStores.isPrivate()) ? UserStore.getUser(stateFromStores.getRecipientId()) : void 0);
|
|
const stateFromStores3 = useStateFromStores([ReadStateStore], () => stateFromStores != null ? ReadStateStore.getMentionCount(stateFromStores.id) : 0);
|
|
const r43 = stateFromStores?.type === ChannelTypes.DM && stateFromStores2 != null ? <Avatar style={styles.privateChannelIcon} user={stateFromStores2} guildId={void 0} size={AvatarSizes.LARGE_48} /> : (stateFromStores == null ? void 0 : stateFromStores.isGroupDM()) ? <GroupDMAvatar channel={stateFromStores} size={AvatarSizes.LARGE_48} /> : stateFromStores != null ? <FastImage style={[styles.privateChannelIcon]} source={getChannelIconSource(stateFromStores)} /> : void 0;
|
|
const callback2 = useCallback(() => {
|
|
L5: {
|
|
if (stateFromStores != null) {
|
|
if (stateFromStores.type === ChannelTypes.DM && stateFromStores2 != null) {
|
|
ChannelActionCreators.openPrivateChannel({
|
|
recipientIds: [stateFromStores2.id]
|
|
});
|
|
break L5;
|
|
}
|
|
transitionToChannel(stateFromStores.id, {
|
|
navigationReplace: true
|
|
});
|
|
}
|
|
}
|
|
}, [stateFromStores2, stateFromStores]);
|
|
return stateFromStores != null ? <Pressable onPress={callback2} style={styles.privateChannelWrapper} accessibilityRole="button" accessible>
|
|
{r43}
|
|
{stateFromStores3 > 0 && <View style={styles.badgeWrapper}>
|
|
<MaskedBadge value={stateFromStores3} unread backgroundColor={styles.maskStrokeStyle.backgroundColor} />
|
|
</View>}
|
|
</Pressable> : null;
|
|
});
|
|
const r68 = memo(function LaunchPadUnreadServers(props) {
|
|
let r67;
|
|
let ref2;
|
|
const { selectedGuildId, setSelectedGuild, unreadPrivateChannelIds, unreadGuilds, guildHistory, visible } = props;
|
|
ref2 = void 0;
|
|
const styles = useStyles();
|
|
const styles2 = useCategoryStyles();
|
|
const isRefreshEnabled = MobileVisualRefreshExperiment("LaunchPadUnreadServers");
|
|
const width = useWindowDimensions_native().width;
|
|
const ref = useRef(-1);
|
|
const callback = useCallback((a0) => {
|
|
if (!(ref.current >= 0) && isGuildSelectable(a0)) {
|
|
setSelectedGuild(a0 !== selectedGuildId ? a0 : void 0);
|
|
ref.current = setTimeout(() => {
|
|
clearTimeout(ref.current);
|
|
ref.current = -1;
|
|
}, 400);
|
|
return void 0;
|
|
}
|
|
clearTimeout(ref.current);
|
|
ref.current = -1;
|
|
transitionToGuild(a0);
|
|
}, [setSelectedGuild, selectedGuildId]);
|
|
useEffect(() => () => clearTimeout(ref.current), []);
|
|
ref2 = useRef(null);
|
|
useEffect(() => {
|
|
if (visible) {
|
|
const current = ref2.current;
|
|
if (current != null) {
|
|
current.scrollToTop(false);
|
|
}
|
|
}
|
|
}, [visible]);
|
|
const callback2 = useCallback((a0, a1) => {
|
|
if (a0 === 0) {
|
|
const channelId2 = unreadPrivateChannelIds[a1];
|
|
return channelId2 != null && <PrivateChannelItemInner channelId={channelId2} />;
|
|
}
|
|
if (a0 >= 1) {
|
|
const guildId2 = a0 === 1 ? unreadGuilds[a1] : guildHistory[a1];
|
|
return guildId2 != null && <GuildItemInner guildId={guildId2} selected={selectedGuildId === guildId2} onGuildSelect={callback} />;
|
|
}
|
|
return null;
|
|
}, [unreadGuilds, unreadPrivateChannelIds, selectedGuildId, callback, guildHistory]);
|
|
const callback3 = useCallback((a0) => {
|
|
let r0;
|
|
L5: {
|
|
r0 = 0;
|
|
if (a0 === 2) {
|
|
const r3 = guildHistory.length > 0;
|
|
r0 = 0;
|
|
if (r3) {
|
|
if (!(unreadPrivateChannelIds.length > 0)) {
|
|
const r12 = unreadGuilds.length > 0;
|
|
r0 = 0;
|
|
if (!r12) {
|
|
break L5;
|
|
}
|
|
}
|
|
r0 = 10;
|
|
}
|
|
}
|
|
}
|
|
return r0;
|
|
}, [unreadGuilds.length, unreadPrivateChannelIds.length, guildHistory.length]);
|
|
const r2 = unreadGuilds.length > 0 || unreadPrivateChannelIds.length > 0;
|
|
L8: {
|
|
if (!r2) {
|
|
const r4 = guildHistory.length > 0;
|
|
r67 = null;
|
|
if (!r4) {
|
|
break L8;
|
|
}
|
|
}
|
|
r67 = <View style={styles.listWrapper}>
|
|
{renderCategoryItem({
|
|
name: r2 ? intl.string(t.xSY9BH) : intl.string(t.kCt2zG),
|
|
styles: styles2,
|
|
isRefreshEnabled
|
|
})}
|
|
<AnimatedFastList ref={ref2} style={styles.list} horizontal renderItem={callback2} renderSection={renderHistorySection} sectionSize={callback3} sections={[unreadPrivateChannelIds.length, unreadGuilds.length, guildHistory.length]} itemSize={58} headerSize={19} footerSize={19} chunkBase={width} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} stickySectionsVariant="disabled" keyboardShouldPersistTaps="always" />
|
|
</View>;
|
|
}
|
|
return r67;
|
|
});
|
|
export default r68;
|