Files
discord-decomp/modules/channel/SelectedChannelManager.tsx
T
2026-11-01 12:12:55 +02:00

52 lines
2.2 KiB
TypeScript

// Metro module 16314 (f16315).
import MediaEngineStore from "../../stores/MediaEngineStore";
import SelectedChannelStore, { findFirstVoiceChannelId } from "../../stores/SelectedChannelStore";
import SelectedGuildStore from "../../stores/SelectedGuildStore";
import { ChannelTypes, ME, NULL_STRING_GUILD_ID, Routes } from "../../Constants";
import AutomaticLifecycleManager from "../../lib/AutomaticLifecycleManager";
import { transitionToGuild } from "../routing/transitionToGuild.native";
import SelectedChannelActionCreators from "../../actions/SelectedChannelActionCreators";
import { transitionTo } from "../routing/router_utils";
import Dispatcher from "../../Dispatcher";
class SelectedChannelManager extends AutomaticLifecycleManager {
actions = {
GUILD_CREATE: this.handleGuildCreate,
CHANNEL_CREATE: this.handleChannelCreate,
LOGOUT: this.handleLogout
};
handleGuildCreate({ guild }) {
const channelId = SelectedChannelStore.getChannelId(ME);
const voiceChannelId = SelectedChannelStore.getVoiceChannelId();
if (guild.id === channelId) {
transitionToGuild(guild.id);
}
if (guild.id === voiceChannelId && guild.unavailable !== false && voiceChannelId == null) {
SelectedChannelActionCreators.selectVoiceChannel(findFirstVoiceChannelId(guild.id));
}
}
handleChannelCreate({ channel }) {
if (channel.type === ChannelTypes.GROUP_DM) {
const originChannelId = channel.originChannelId;
const channelId = SelectedChannelStore.getChannelId(NULL_STRING_GUILD_ID);
if (SelectedGuildStore.getGuildId() == null && originChannelId != null && originChannelId === channelId) {
transitionTo(Routes.CHANNEL(ME, channel.id));
}
if (originChannelId != null && originChannelId === SelectedChannelStore.getVoiceChannelId()) {
SelectedChannelActionCreators.selectVoiceChannel(channel.id, MediaEngineStore.isVideoEnabled());
}
}
}
handleLogout() {
Dispatcher.dispatch({
type: "VOICE_CHANNEL_SELECT",
channelId: null,
guildId: null,
video: false,
currentVoiceChannelId: null,
joinVoiceId: null
});
}
}
const selectedChannelManager = new SelectedChannelManager();
export default selectedChannelManager;