Files
discord-decomp/modules/voice_panel/native/shared/VoicePanelTitleButton.tsx
T
2026-11-01 12:12:55 +02:00

160 lines
7.2 KiB
TypeScript

// Metro module 15933 (f15934).
import { useContext, memo, useCallback } from "react";
import { View } from "react-native";
import ApplicationStore from "../../../applications/ApplicationStore";
import StageInstanceStore from "../../../stage_channels/StageInstanceStore";
import ChannelStore from "../../../../stores/ChannelStore";
import { ParticipantTypes } from "../../../calls/CallConstants";
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
import { ShieldLockIcon } from "../../../../design/components/Icon/native/redesign/generated/ShieldLockIcon";
import { intl, t } from "../../../../intl/index.native";
import { BaseTextButton } from "../../../../design/components/Button/native/BaseTextButton.native";
import Module5229 from "../../../../_bundle/Module5229";
import { useStateFromStores } from "../../../../_bundle/Module589";
import useChannelName from "../../../channel/useChannelName";
import { useIsCallSecureFramesVerified } from "../../../rtc/hooks/useIsSecureFramesVerified";
import { HeaderButton } from "../../../../design/components/experimental/native";
import Module712 from "../../../../_bundle/Module712";
import VoicePanelStateContext from "../VoicePanelStateContext";
import NicknameUtils from "../../../../utils/NicknameUtils";
import Module15934 from "../../../../_bundle/Module15934";
import { Stack } from "../../../../design/components/Stack/native/Stack.native";
import Module6614 from "../../../../_bundle/Module6614";
import QuestActivityButton from "../../../frames/panel/native/QuestActivityButton";
import { useVoicePanelHeaderUserStateIcons } from "../header/VoicePanelHeaderUserState";
import Module4658 from "../../../../_bundle/Module4658";
import { useDerivedStateFromSharedValue } from "../../../reanimated/native/useStateFromSharedValue";
import { ChannelTypes } from "../../../../_bundle/Module692";
import useStableParticipant from "../utils/useStableParticipant";
import { openVoicePanelSettingsActionSheet } from "../header/VoicePanelSettingsActionCreators";
let useStyles, ChannelButton, StreamButton, ActivityButton, UserButton, StageButton;
const ChannelButtonIcons = function ChannelButtonIcons() {
return <View style={useStyles().channelButtons}>
<ShieldLockIcon size="xs" accessibilityLabel={intl.string(t.VHXh8a)} />
<BaseTextButton.Icon source={Module5229} />
</View>;
};
ChannelButton = function ChannelButton(props) {
const { channelId, onPress } = props;
let text = useChannelName(useStateFromStores([ChannelStore], () => ChannelStore.getChannel(channelId)));
const isCallSecureFramesVerified = useIsCallSecureFramesVerified({
channelId
});
const props2 = {
accessibilityRole: "button",
accessibilityHint: intl.string(t["Y2b7+e"]),
text: null,
icon: null,
iconOpticalOffsetMargin: null,
iconPosition: "end",
onPress: null,
maxFontSizeMultiplier: 2
};
if (text == null) {
text = "???";
}
props2.text = text;
props2.icon = isCallSecureFramesVerified ? <ChannelButtonIcons /> : Module5229;
props2.iconOpticalOffsetMargin = -Module712.space.PX_4;
props2.onPress = onPress;
return <HeaderButton {...props2} />;
};
StreamButton = function StreamButton(props) {
const { participant: participant2, onPress } = props;
const context = useContext(VoicePanelStateContext);
const name = NicknameUtils.useName(context.guildId, context.channelId, participant2.user);
return <HeaderButton accessibilityRole="button" accessibilityHint={intl.string(t["Y2b7+e"])} accessibilityLabel={intl.formatToPlainString(t.I0mOAs, {
username: name
})} text={name} icon={Module15934} iconPosition="start" onPress={onPress} />;
};
ActivityButton = function ActivityButton(props) {
const { participant, onPress } = props;
const stateFromStores = useStateFromStores([ApplicationStore], () => ApplicationStore.getApplication(participant.applicationId));
const props2 = {
accessibilityRole: "button",
accessibilityHint: intl.string(t["Y2b7+e"]),
text: null,
icon: null,
iconPosition: "start",
onPress: null,
shrink: true
};
let text = stateFromStores?.name;
if (text == null) {
text = "???";
}
props2.text = text;
props2.icon = Module6614;
props2.onPress = onPress;
return <Stack direction="horizontal" spacing={Module712.space.PX_8}>
<HeaderButton {...props2} />
<QuestActivityButton applicationId={participant.applicationId} />
</Stack>;
};
UserButton = function UserButton(props) {
const { participant: participant2, onPress } = props;
const styles = useStyles();
const context = useContext(VoicePanelStateContext);
const guildId2 = context.guildId;
const name = NicknameUtils.useName(guildId2, context.channelId, participant2.user);
const voicePanelHeaderUserStateIcons = useVoicePanelHeaderUserStateIcons(participant2, guildId2, styles.userIcons);
return <HeaderButton accessibilityRole="button" accessibilityHint={intl.string(t["Y2b7+e"])} icon={voicePanelHeaderUserStateIcons} iconPosition={voicePanelHeaderUserStateIcons != null ? "start" : void 0} text={name} onPress={onPress} />;
};
StageButton = function StageButton(props) {
const { channelId: channelId2, onPress } = props;
const stateFromStores = useStateFromStores([StageInstanceStore], () => StageInstanceStore.getStageInstanceByChannel(channelId2), [channelId2]);
const channelName = useChannelName(useStateFromStores([ChannelStore], () => ChannelStore.getChannel(channelId2)));
const props2 = {
accessibilityRole: "button",
accessibilityHint: intl.string(t["Y2b7+e"]),
text: null,
icon: null,
iconPosition: "start",
onPress: null
};
let text = stateFromStores?.topic;
if (text == null) {
text = channelName;
}
if (text == null) {
text = intl.string(t.zLZPmk);
}
props2.text = text;
props2.icon = Module4658;
props2.onPress = onPress;
return <HeaderButton {...props2} />;
};
useStyles = createStyles({
userIcons: {
marginLeft: -6
},
channelButtons: {
alignItems: "center",
flexDirection: "row",
gap: 2
}
});
const r46 = memo(function VoicePanelTitleButton() {
const context = useContext(VoicePanelStateContext);
const { guildId, channelId: channelId3, channelType } = context;
const derivedStateFromSharedValue = useDerivedStateFromSharedValue(context.focused, (a0) => a0?.id);
const GUILD_STAGE_VOICE = ChannelTypes.GUILD_STAGE_VOICE;
const stableParticipant = useStableParticipant(derivedStateFromSharedValue, channelId3, guildId);
const callback = useCallback(() => {
openVoicePanelSettingsActionSheet(guildId, channelId3);
}, [guildId, channelId3]);
if (stableParticipant != null) {
if (stableParticipant.type === ParticipantTypes.STREAM) {
return <StreamButton participant={stableParticipant} onPress={callback} />;
}
if (stableParticipant.type === ParticipantTypes.ACTIVITY) {
return <ActivityButton participant={stableParticipant} onPress={callback} />;
}
if (stableParticipant.type === ParticipantTypes.USER) {
return <UserButton participant={stableParticipant} onPress={callback} />;
}
}
return channelType === GUILD_STAGE_VOICE ? <StageButton channelId={channelId3} onPress={callback} /> : <ChannelButton channelId={channelId3} onPress={callback} />;
});
export default r46;