131 lines
4.6 KiB
TypeScript
131 lines
4.6 KiB
TypeScript
// Metro module 10485 (f10486).
|
|
import _slicedToArray from "../../../_bundle/_slicedToArray";
|
|
import { useMemo, useRef, useEffect, useState, useCallback } from "react";
|
|
import { findNodeHandle } from "react-native";
|
|
import VoiceChannelStartTimeStore from "../../channel/VoiceChannelStartTimeStore";
|
|
import { updateShouldShowJumpToPresentButton } from "../../chat_input/native/useChatBottomManagerUIStore";
|
|
import GuildAvailabilityStore from "../../../stores/GuildAvailabilityStore";
|
|
import GuildStore from "../../../stores/GuildStore";
|
|
import PresenceStore from "../../../stores/PresenceStore";
|
|
import { useStateFromStoresObject } from "../../../_bundle/Module589";
|
|
import Module12 from "../../../_bundle/Module12";
|
|
import { areArraysShallowEqual } from "../../../_bundle/shallowEqual";
|
|
import ApplicationActionCreators from "../../applications/ApplicationActionCreators";
|
|
import { isNotNullish } from "../../../utils/GlobalUtils";
|
|
import { isVoiceChannelInvite } from "../../instant_invite/InviteTypeUtils";
|
|
import { fetchChannelInfo } from "../../channel/ChannelInfoActionCreators";
|
|
import { syncMessageDisplay, recordTimings } from "./MessagesUtils";
|
|
import ChatUpdatesQueue from "../../chat/native/ChatUpdatesQueue";
|
|
export function useMessageAuthorActivities(a0) {
|
|
let c18001_0 = a0;
|
|
const memo = useMemo(() => {
|
|
const r0 = {};
|
|
let c26685_0 = r0;
|
|
c18001_0.forEach((item) => {
|
|
if (item.author != null && item.activity != null) {
|
|
c26685_0[item.author.id] = null;
|
|
}
|
|
});
|
|
return r0;
|
|
}, [a0]);
|
|
return useStateFromStoresObject([PresenceStore], () => Module12.mapValues(memo, (a0, a1) => PresenceStore.getPrimaryActivity(a1)), [memo]);
|
|
}
|
|
export function useFetchMessageApplications(a0) {
|
|
let ref;
|
|
const memo2 = useMemo(() => {
|
|
const set = new Set();
|
|
let c26686_0 = set;
|
|
a0.forEach((item) => {
|
|
if (item.applicationId != null && item.application == null) {
|
|
c26686_0.add(item.applicationId);
|
|
}
|
|
});
|
|
return Array.from(set);
|
|
}, [a0]);
|
|
ref = useRef([]);
|
|
useEffect(() => {
|
|
if (!areArraysShallowEqual(memo2, ref.current)) {
|
|
ApplicationActionCreators.fetchApplications(Module12(memo2).filter(isNotNullish).uniq().value(), false);
|
|
ref.current = memo2;
|
|
}
|
|
}, [memo2]);
|
|
}
|
|
export function useFetchVoiceChannelInviteStartTimes(a0) {
|
|
const stateFromStoresObject = useStateFromStoresObject([GuildStore, GuildAvailabilityStore], () => {
|
|
const r0 = {};
|
|
for (const item of a0.values()) {
|
|
if (item.guild != null && isVoiceChannelInvite(item)) {
|
|
const id = item.guild.id;
|
|
r0[id] = GuildStore.getGuild(id) != null && !GuildAvailabilityStore.isUnavailable(id);
|
|
}
|
|
}
|
|
return r0;
|
|
}, [a0]);
|
|
useEffect(() => {
|
|
for (const item of a0.values()) {
|
|
if (item.guild != null && isVoiceChannelInvite(item)) {
|
|
const id = item.guild.id;
|
|
if (!(stateFromStoresObject[id] !== true || VoiceChannelStartTimeStore.hasRequestedStartTimes(id))) {
|
|
fetchChannelInfo(id);
|
|
}
|
|
}
|
|
}
|
|
}, [a0, stateFromStoresObject]);
|
|
}
|
|
export function useMessagesLifecycle({ messages, isMessagesReady, oldestUnreadMessageId, channelId, screenIndex, updateRows, scrollToMessageId }) {
|
|
useEffect(() => {
|
|
syncMessageDisplay({
|
|
messages,
|
|
isMessagesReady,
|
|
oldestUnreadMessageId,
|
|
channelId,
|
|
screenIndex,
|
|
updateRows,
|
|
scrollToMessageId
|
|
});
|
|
recordTimings(channelId, messages);
|
|
}, []);
|
|
useEffect(() => () => {
|
|
updateShouldShowJumpToPresentButton(channelId, screenIndex, false);
|
|
}, [channelId, screenIndex]);
|
|
}
|
|
export function useScrollState() {
|
|
const [state, setState] = useState({
|
|
animated: false,
|
|
hasHandledScroll: false,
|
|
isAtBottom: false,
|
|
isNearBottom: false,
|
|
isNearTop: false,
|
|
decelerating: false,
|
|
dragging: false,
|
|
hasMoreMessagesAfterForLastUpdate: false,
|
|
_loaded: false
|
|
});
|
|
return [state, useCallback((c26687_0) => {
|
|
setState((prevState) => ({
|
|
...prevState,
|
|
...c26687_0
|
|
}));
|
|
}, [])];
|
|
}
|
|
export function useChatUpdatesQueue(a0, a1) {
|
|
let c18006_0 = a0;
|
|
const memo3 = useMemo(() => new ChatUpdatesQueue(() => c18006_0.current !== null ? findNodeHandle(c18006_0.current) : null, (a0) => {
|
|
a1(a0);
|
|
}), [a0, a1]);
|
|
useEffect(() => () => {
|
|
memo3.cleanup();
|
|
}, [memo3]);
|
|
return memo3;
|
|
}
|
|
export function useMessagesState() {
|
|
const [shouldForceRender, setShouldForceRender] = useState(false);
|
|
const r13 = _slicedToArray(useState(false), 2);
|
|
return {
|
|
shouldForceRender,
|
|
hasJumpedToOriginalPost: r13[0],
|
|
setHasJumpedToOriginalPost: r13[1],
|
|
setShouldForceRender
|
|
};
|
|
}
|