Files
discord-decomp/modules/guild_sidebar/native/ChannelItem.tsx
T
2026-11-01 12:12:55 +02:00

142 lines
6.7 KiB
TypeScript

// Metro module 15104 (f15105).
import { memo } from "react";
import { View } from "react-native";
import PresenceStore from "../../../stores/PresenceStore";
import RelationshipStore from "../../../stores/RelationshipStore";
import UserStore from "../../../stores/UserStore";
import { ChannelTypes, Routes } from "../../../Constants";
import { StaticChannelRoute } from "../../channel/ChannelConstants";
import { UnreadSetting } from "../../read_states/ReadStateConstants";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import { DARK_393C42_LIGHT_DEE0E4 } from "../../../design/migrations/native/LegacyTokens";
import BaseChannelItem, { ChannelModes, BaseChannelIcon, BaseChannelName } from "./BaseChannelItem";
import AvatarUtils from "../../../utils/AvatarUtils";
import FastImage from "../../../components_native/common/FastImage";
import Module15105 from "../../../_bundle/Module15105";
import { BookCheckIcon } from "../../../design/components/Icon/native/redesign/generated/BookCheckIcon";
import { getChannelIcon, getChannelIconComponent } from "../../../utils/native/ChannelUtils";
import { useStateFromStores, useStateFromStoresObject } from "../../../_bundle/Module589";
import { Avatar, AvatarSizes } from "../../../design/void/native";
import useChannelRoleSubscriptionStatus from "../../guild_role_subscriptions/useChannelRoleSubscriptionStatus";
import GuildRoleSubscriptionGatedChannelIcon from "../../guild_role_subscriptions/native/premium_channel/GuildRoleSubscriptionGatedChannelIcon";
import { computeChannelName } from "../../channel/useChannelName";
import { transitionTo } from "../../routing/router_utils";
let _excluded, c10706_15, useStyles, ChannelIcon, DMChannelIcon;
const getChannelMode = function getChannelMode(a0) {
const { muted, selected, unread, locked, channel: channel2 } = a0;
return selected ? channel2.isGuildVocal() ? unread ? ChannelModes.UNREAD_IMPORTANT : ChannelModes.RELEVANT : ChannelModes.SELECTED : locked ? ChannelModes.LOCKED : muted ? ChannelModes.MUTED : unread ? a0.resolvedUnreadSetting === UnreadSetting.ALL_MESSAGES ? ChannelModes.UNREAD_IMPORTANT : ChannelModes.UNREAD_LESS_IMPORTANT : ChannelModes.DEFAULT;
};
ChannelIcon = function ChannelIcon(props) {
let BookCheckIcon2, source;
const styles = useStyles();
const { channel: channel2, locked, isRulesChannel, isChannelLive } = props;
let selected = props.selected;
const mode = props.mode;
if (channel2.type === ChannelTypes.DM) {
const props2 = {
userId: channel2.getRecipientId(),
selected: null
};
if (selected == null) {
selected = false;
}
props2.selected = selected;
return <DMChannelIcon {...props2} />;
}
if (channel2.type === ChannelTypes.GROUP_DM) {
const channelIconSource = AvatarUtils.getChannelIconSource({
id: channel2.id,
icon: channel2.icon,
applicationId: channel2.getApplicationId(),
size: 20
});
if (channelIconSource != null) {
return <FastImage style={styles.groupDmAvatar} source={channelIconSource} />;
}
}
if (isRulesChannel) {
source = Module15105;
BookCheckIcon2 = BookCheckIcon;
} else {
const channelIcon = getChannelIcon(channel2, {
isRulesChannel: false,
locked
});
BookCheckIcon2 = getChannelIconComponent(channel2, {
isRulesChannel: false,
locked
});
source = channelIcon;
}
return <BaseChannelIcon mode={mode} source={source} isChannelLive={isChannelLive} style={isChannelLive ? styles.channelIconLive : void 0} {...BookCheckIcon2 != null ? {
IconComponent: BookCheckIcon2
} : {}} />;
};
DMChannelIcon = function DMChannelIcon(props) {
const userId = props.userId;
let selected = props.selected;
const styles = useStyles();
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getUser(userId), [userId]);
const stateFromStoresObject = useStateFromStoresObject([PresenceStore], () => ({
status: PresenceStore.getStatus(userId),
isMobileOnline: PresenceStore.isMobileOnline(userId),
isVROnline: PresenceStore.isVROnline(userId)
}), [userId]);
const { status, isMobileOnline } = stateFromStoresObject;
const statusStyle = [styles.avatarStatus, ,];
if (selected) {
selected = styles.avatarStatusSelected;
}
statusStyle[1] = selected;
return <Avatar user={stateFromStores} guildId={void 0} size={AvatarSizes.XSMALL_20} style={styles.dmAvatar} status={status} isMobileOnline={isMobileOnline} isVROnline={stateFromStoresObject.isVROnline} statusStyle={statusStyle} />;
};
_excluded = ["channel", "subtitle", "hideIcon", "children", "textStyle", "channelInfo", "onPress"];
c10706_15 = new Set([ChannelTypes.GUILD_VOICE, ChannelTypes.GUILD_STAGE_VOICE]);
useStyles = createStyles({
channelIconLive: {
tintColor: Module712.unsafe_rawColors.GREEN_360
},
dmAvatar: {
marginRight: 8
},
avatarStatus: {
backgroundColor: Module712.colors.BACKGROUND_BASE_LOW
},
groupDmAvatar: {
width: 20,
height: 20,
borderRadius: 10,
marginRight: 8
},
channelInfoContainer: {
paddingStart: 4
},
avatarStatusSelected: {
backgroundColor: DARK_393C42_LIGHT_DEE0E4
}
});
const r79 = memo(function(a0) {
const styles = useStyles();
const { channel, subtitle, hideIcon, children, textStyle, channelInfo, onPress: onPress2, ...rest } = a0;
const channelRoleSubscriptionStatus = useChannelRoleSubscriptionStatus(channel.id);
const { isSubscriptionGated, needSubscriptionToAccess } = channelRoleSubscriptionStatus;
const channelMode = getChannelMode(a0);
const channelInfo2 = channelInfo == null ? isSubscriptionGated ? <View style={styles.channelInfoContainer}>
{channelInfo}
{isSubscriptionGated ? <GuildRoleSubscriptionGatedChannelIcon locked={needSubscriptionToAccess} /> : null}
</View> : null : <View style={styles.channelInfoContainer}>
{channelInfo}
{isSubscriptionGated ? <GuildRoleSubscriptionGatedChannelIcon locked={needSubscriptionToAccess} /> : null}
</View>;
return <BaseChannelItem mode={channelMode} unread={channelMode === ChannelModes.UNREAD_IMPORTANT || channelMode === ChannelModes.UNREAD_LESS_IMPORTANT} hideIcon={hideIcon} name={<BaseChannelName mode={channelMode} name={computeChannelName(channel, UserStore, RelationshipStore)} subtitle={subtitle} textStyle={textStyle} />} icon={<ChannelIcon {...a0} mode={channelMode} />} channelInfo={channelInfo2} onPress={function onPress(event) {
if (needSubscriptionToAccess && c10706_15.has(channel.type)) {
transitionTo(Routes.CHANNEL(channel.guild_id, StaticChannelRoute.ROLE_SUBSCRIPTIONS));
} else if (onPress2 != null) {
onPress2(event);
}
}} {...rest}>{children}</BaseChannelItem>;
});
export default r79;
export { getChannelMode };