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

174 lines
4.4 KiB
TypeScript

// Metro module 4042 (f4043).
import AuthenticationStore from "../../../stores/AuthenticationStore";
import DefaultRouteStore from "../../../stores/DefaultRouteStore";
import SelectedChannelStore from "../../../stores/SelectedChannelStore";
import { ME, Routes } from "../../../Constants";
import Logger from "../../debug/Logger";
import { getChatLayout } from "../../chat/native/useChatLayout";
import { getHistory } from "../../routing/router_utils";
import { matchPath } from "../../routing/matchPathCompat";
import { RouteParam } from "../../routing/RouteUtils";
import { MobileHomeDrawerExperiment } from "../../home_drawer/native/HomeDrawerExperiment";
let c2319_8, computeInitialNavigationStateWithoutLogging;
const getInitialGuildState = function getInitialGuildState(a0, a1, a2, drawerOpen = false) {
let r32;
let channelId = a1 == null ? SelectedChannelStore.getChannelId(a0) : a1;
if (channelId == null) {
channelId = void 0;
}
const isChatLockedOpen = getChatLayout().isChatLockedOpen;
if (a2 && (channelId != null && (!isChatLockedOpen && !drawerOpen))) {
const routes = [{
name: "tabs",
state: {
routes: [{
name: "guilds",
params: {
guildId: a0,
channelId
}
}],
index: 0
}
}, {
name: "channel",
params: {
guildId: a0,
channelId
}
}];
r32 = [true, {
index: 0,
routes: [{
name: "main",
state: {
routes,
index: routes.length - 1
}
}]
}];
} else {
const r34 = !!isChatLockedOpen && channelId != null;
const routes2 = [{
name: "tabs",
state: {
routes: [{
name: "guilds",
params: {
guildId: a0,
channelId,
drawerOpen
}
}],
index: 0
}
}];
r32 = [r34, {
index: 0,
routes: [{
name: "main",
state: {
routes: routes2,
index: routes2.length - 1
}
}]
}];
}
return r32;
};
computeInitialNavigationStateWithoutLogging = function computeInitialNavigationStateWithoutLogging() {
let r54, r55;
if (AuthenticationStore.getToken() != null) {
const location2 = getHistory().location;
const r46 = matchPath(location2.pathname, {
path: Routes.CHANNEL(RouteParam.guildId(), RouteParam.channelId({
optional: true
}), ":messageId?")
});
const r53 = MobileHomeDrawerExperiment.getConfig({
location: "app-start"
}).landOnHome && r46 == null;
if (r46 == null) {
r55 = matchPath(DefaultRouteStore.lastNonVoiceRoute, {
path: Routes.CHANNEL(RouteParam.guildId(), RouteParam.channelId({
optional: true
}), ":messageId?")
});
r54 = false;
} else {
r54 = location2.openChannel;
if (r54 == null) {
r54 = false;
}
r55 = r46;
}
let r74 = r55?.params;
if (r74 == null) {
r74 = {};
}
const { channelId, guildId } = r74;
if (guildId == null) {
const r93 = [{
page: "private-channels"
}, ,];
let r94 = r53;
if (r94 === void 0) {
r94 = false;
}
r93[1] = getInitialGuildState(ME, void 0, false, r94)[1];
return r93;
}
if (!r54) {
r54 = guildId !== ME;
}
const [r82, r83] = getInitialGuildState(guildId, channelId, r54, r53);
const page = r82 ? "other" : guildId === ME ? "private-channels" : "guild-channels";
return page === "private-channels" ? [{
page
}, r83] : [{
page,
guildId
}, r83];
}
return [{
page: "other"
}, {
routes: [{
name: "auth"
}],
index: 0
}];
};
c2319_8 = new Logger("getInitialNavigationState");
export default function getInitialNavigationState(a0) {
const r8 = computeInitialNavigationStateWithoutLogging()[1];
let c13803_0 = r8;
if (a0 != null) {
a0.forEach((item) => c13803_0.routes.push(item));
}
return r8;
};
export function wrapRouteForRootNavigator(a0) {
return [{
name: "main",
state: {
routes: a0,
index: a0.length - 1
}
}];
}
export function getInitialAuthState() {
return {
routes: [{
name: "auth"
}],
index: 0
};
}
export { getInitialGuildState };
export function computeInitialNavigationState() {
const r5 = computeInitialNavigationStateWithoutLogging();
c2319_8.log("Initial State:", r5);
return r5;
}