153 lines
4.8 KiB
TypeScript
153 lines
4.8 KiB
TypeScript
// Metro module 10253 (f10254).
|
|
import { useState, useEffect } from "react";
|
|
import ChannelRTCStore from "../calls/ChannelRTCStore";
|
|
import NavigationHistoryStore, { CHANNEL_PREFIX } from "../main_tabs_v2/native/NavigationHistoryStore";
|
|
import VoicePanelStore from "../voice_panel/VoicePanelStore";
|
|
import getInitialNavigationState from "../main_tabs_v2/native/getInitialNavigationState";
|
|
import { coerceChannelRoute, coerceGuildsRoute, coerceMainRoute, coerceTabsRoute } from "../main_tabs_v2/helpers/NavigationRouteUtils.native";
|
|
import { getRootNavigationRef } from "../main_tabs_v2/RootNavigationRef.native";
|
|
import useChatLayout, { getChatLayout } from "../chat/native/useChatLayout";
|
|
let channelId;
|
|
const getFocusedChannelId = function getFocusedChannelId() {
|
|
const rootNavigationRef2 = getRootNavigationRef();
|
|
const isChatLockedOpen = getChatLayout().isChatLockedOpen;
|
|
if (rootNavigationRef2 != null && rootNavigationRef2.isReady()) {
|
|
const currentRoute = rootNavigationRef2.getCurrentRoute();
|
|
const r28 = coerceChannelRoute(currentRoute);
|
|
if (r28 != null) {
|
|
return r28.params.channelId;
|
|
}
|
|
if (isChatLockedOpen) {
|
|
const r31 = coerceGuildsRoute(currentRoute);
|
|
return r31 != null ? r31.params?.channelId : void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
let r38 = channelId;
|
|
if (r38 === null) {
|
|
const initialNavigationState = getInitialNavigationState();
|
|
const r45 = initialNavigationState == null;
|
|
let r46 = void 0;
|
|
if (!r45) {
|
|
const routes = initialNavigationState.routes;
|
|
const r47 = routes == null;
|
|
r46 = void 0;
|
|
if (!r47) {
|
|
let r12 = initialNavigationState?.index;
|
|
if (r12 == null) {
|
|
r12 = 0;
|
|
}
|
|
r46 = routes[r12];
|
|
}
|
|
}
|
|
const r49 = coerceMainRoute(r46);
|
|
const r50 = r49 != null;
|
|
let r51 = void 0;
|
|
if (r50) {
|
|
if (isChatLockedOpen) {
|
|
const state2 = r49.state;
|
|
const r69 = state2 == null;
|
|
let r70 = void 0;
|
|
if (!r69) {
|
|
const routes3 = state2.routes;
|
|
const r72 = routes3 == null;
|
|
r70 = void 0;
|
|
if (!r72) {
|
|
let r75 = r49.state?.index;
|
|
if (r75 == null) {
|
|
r75 = 0;
|
|
}
|
|
r70 = routes3[r75];
|
|
}
|
|
}
|
|
const r76 = coerceTabsRoute(r70);
|
|
const r77 = r76 != null;
|
|
r51 = void 0;
|
|
if (r77) {
|
|
const state3 = r76.state;
|
|
const r82 = state3 == null;
|
|
let r83 = void 0;
|
|
if (!r82) {
|
|
const routes4 = state3.routes;
|
|
const r85 = routes4 == null;
|
|
r83 = void 0;
|
|
if (!r85) {
|
|
let r88 = r76.state?.index;
|
|
if (r88 == null) {
|
|
r88 = 0;
|
|
}
|
|
r83 = routes4[r88];
|
|
}
|
|
}
|
|
const r89 = coerceGuildsRoute(r83);
|
|
r51 = r89 != null ? r89.params?.channelId : void 0;
|
|
}
|
|
} else {
|
|
const state = r49.state;
|
|
const r56 = state == null;
|
|
let r57 = void 0;
|
|
if (!r56) {
|
|
const routes2 = state.routes;
|
|
const r59 = routes2 == null;
|
|
r57 = void 0;
|
|
if (!r59) {
|
|
let r61 = r49.state?.index;
|
|
if (r61 == null) {
|
|
r61 = 0;
|
|
}
|
|
r57 = routes2[r61];
|
|
}
|
|
}
|
|
const r62 = coerceChannelRoute(r57);
|
|
r51 = r62 == null ? void 0 : r62.params?.channelId;
|
|
}
|
|
}
|
|
channelId = r51;
|
|
r38 = r51;
|
|
}
|
|
return r38;
|
|
};
|
|
channelId = null;
|
|
export { getFocusedChannelId };
|
|
export function isChannelFocused() {
|
|
return getFocusedChannelId() != null;
|
|
}
|
|
export function useIsChannelFocused() {
|
|
const [state, setState] = useState(() => getFocusedChannelId() != null);
|
|
useEffect(() => {
|
|
setState(getFocusedChannelId() != null);
|
|
}, [useChatLayout()]);
|
|
useEffect(() => {
|
|
let rootNavigationRef;
|
|
const handleStateChange2 = function handleStateChange() {
|
|
setState(getFocusedChannelId() != null);
|
|
};
|
|
rootNavigationRef = getRootNavigationRef();
|
|
if (rootNavigationRef != null) {
|
|
rootNavigationRef.addListener("state", handleStateChange2);
|
|
return () => {
|
|
rootNavigationRef.removeListener("state", handleStateChange2);
|
|
};
|
|
}
|
|
}, []);
|
|
return state;
|
|
}
|
|
export function isChannelFocusedForReadStateAck(a0, a1) {
|
|
if (ChannelRTCStore.getChatOpen(a0)) {
|
|
return true;
|
|
}
|
|
if (VoicePanelStore.getState().isVoicePanelFullscreen()) {
|
|
return false;
|
|
}
|
|
if (getFocusedChannelId() === a0) {
|
|
return true;
|
|
}
|
|
if (a1 != null) {
|
|
const lastFocusedTimestampForHistoryItem = NavigationHistoryStore.getLastFocusedTimestampForHistoryItem(CHANNEL_PREFIX + a0);
|
|
if (lastFocusedTimestampForHistoryItem != null && lastFocusedTimestampForHistoryItem >= a1) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|