Files
discord-decomp/modules/messages/native/hooks/useRowManager.tsx
T
2026-11-01 12:12:55 +02:00

322 lines
11 KiB
TypeScript

// Metro module 11144 (f11145).
import TTITracker from "../../../tti_analytics/TTITracker";
import { JumpType } from "../../../../flow/Client";
import NativeChatUtils, { ChatScrollPosition } from "../../../chat/native/NativeChatUtils";
import { isIOS } from "../../../../utils/PlatformUtils";
import computeScrollData from "../../../chat/native/computeScrollData";
function $mk107736($env) {
return () => {
const r4 = $env;
const r0 = $env.$parent;
const chatManager = r0[0];
const messages = r0[5];
chatManager.setup(messages);
r0[1].setOptions({
inlineAttachmentMedia: r0[11],
inlineEmbedMedia: r0[12],
renderEmbeds: r0[13],
renderReactions: r0[14],
animateEmoji: r0[15],
animatingStickerMessageId: r0[2].current,
constrainedWidth: r0[26],
gifAutoPlay: r0[16],
timestampHourCycle: r0[17],
renderCommunicationDisabled: r0[19],
ignoreEmbedDescriptionCache: r4[2],
enableSwipeActions: r0[21],
shouldObscureSpoiler: r0[23],
shouldDisableInteractiveComponents: r0[24]
});
const r36 = $env.$parent.$parent;
for (const item of (0, r36[1])(r36[2][1])({
channel: r0[4],
messages,
uploads: r0[7],
oldestUnreadMessageId: r0[9],
replyingMessageId: r0[10],
currentUserId: r0[18],
canAddNewReactions: (0, r0[3])(),
selectedSummary: r0[20],
chatManager,
roleStyle: r0[8],
forceRender: r4[0],
updateMessageIds: r4[1],
isResourceChannel: r0[22],
unloadableContentEntryMessageIds: r0[25]
})) {
r0[0].createRow(r0[1].generate(item));
}
return r0[0].createChangeset();
};
}
function $mk107737($env) {
return () => {
const r9 = $env;
const r4 = $env.$parent;
const r3 = r4[38];
const scrollToMessageId3 = r9[0];
const r7 = r3(scrollToMessageId3);
if (r7 != null) {
const r11 = r4[27];
if (r11.current != null) {
const r12 = r9[1];
let r13 = false;
if (r12) {
const r14 = r4[42];
const r16 = $env.$parent.$parent;
r14({
scrollToMessageId: scrollToMessageId3,
jumpTargetId: scrollToMessageId3,
jumpType: r9[2],
focusTargetId: scrollToMessageId3,
overrideScrollJumpType: (0, r16[0])(r16[2][2]).JumpType.INSTANT,
isRescrolling: true,
hasJumpedToOriginalPost: r9[3]
});
r13 = true;
}
if (!r13) {
const r24 = $env.$parent.$parent;
(0, r24[1])(r24[2][3]).scrollTo(r11.current, r7, {
animated: r9[2] === (0, r24[0])(r24[2][2]).JumpType.ANIMATED
});
}
}
}
};
}
let env7531 = {};
export default function useRowManager(a0) {
let env18559 = {
$parent: env7531
};
env18559[0] = a0.chatManager;
env18559[1] = a0.rowGenerator;
env18559[2] = a0.animatingStickerMessageIdRef;
env18559[3] = a0.canAddNewReactions;
env18559[4] = a0.channel;
env18559[5] = a0.messages;
env18559[6] = a0.isMessagesReady;
env18559[7] = a0.uploads;
env18559[8] = a0.roleStyle;
env18559[9] = a0.oldestUnreadMessageId;
env18559[10] = a0.replyingMessageId;
env18559[11] = a0.inlineAttachmentMedia;
env18559[12] = a0.inlineEmbedMedia;
env18559[13] = a0.renderEmbeds;
env18559[14] = a0.renderReactions;
env18559[15] = a0.animateEmoji;
env18559[16] = a0.gifAutoPlay;
env18559[17] = a0.timestampHourCycle;
env18559[18] = a0.currentUserId;
env18559[19] = a0.renderCommunicationDisabled;
env18559[20] = a0.selectedSummary;
env18559[21] = a0.enableSwipeActions;
env18559[22] = a0.isResourceChannel;
env18559[23] = a0.shouldObscureSpoiler;
env18559[24] = a0.shouldDisableInteractiveComponents;
env18559[25] = a0.unloadableContentEntryMessageIds;
env18559[26] = a0.containerWidth;
env18559[27] = a0.chatRef;
env18559[28] = a0.loadedRef;
env18559[29] = a0.animatedRef;
env18559[30] = a0.hasMoreMessagesAfterForLastUpdateRef;
env18559[31] = a0.updateNativeRows;
env18559[32] = a0.isLoadingAtTop;
env18559[33] = a0.channelLatestMessageLoadingStatsManager;
env18559[34] = a0.channelId;
env18559[35] = a0.isMessagesCached;
env18559[36] = a0.chatUpdatesQueue;
env18559[37] = a0.shouldJumpToOriginalPost;
env18559[38] = a0.findMessageIndex;
env18559[39] = a0.scrollToTopMessage;
env18559[40] = a0.useReducedMotion;
const scrollToMessageId = function scrollToMessageId(a0) {
let animated, c26950_3;
const { scrollToMessageId: scrollToMessageId2, jumpTargetId = null } = a0;
let c26950_1 = jumpTargetId;
const { jumpType = JumpType.ANIMATED, scrollPosition = ChatScrollPosition.TOP, minimizeScrolling = false, isRescrolling = false } = a0;
let hasJumpedToOriginalPost = a0.hasJumpedToOriginalPost;
if (hasJumpedToOriginalPost === void 0) {
hasJumpedToOriginalPost = false;
}
animated = void 0;
c26950_3 = void 0;
const r13 = env18559[40] || jumpType === JumpType.INSTANT;
L29: {
animated = !r13;
if (isIOS() && !isRescrolling) {
let r46 = r13 ? JumpType.INSTANT : JumpType.ANIMATED;
let env26951;
const r47 = env26951 = {
$parent: env18559
};
env26951[0] = scrollToMessageId2;
env26951[1] = true;
if (r46 === void 0) {
r46 = JumpType.INSTANT;
}
env26951[2] = r46;
if (hasJumpedToOriginalPost === void 0) {
hasJumpedToOriginalPost = false;
}
env26951[3] = hasJumpedToOriginalPost;
if (scrollToMessageId2 == null) {
break L29;
}
setTimeout($mk107737(r47), 50);
} else {
const r59 = (0, env18559[38])(scrollToMessageId2);
c26950_3 = r59;
if (r59 != null) {
if (minimizeScrolling) {
setTimeout(() => {
NativeChatUtils.scrollIntoView(env18559[27].current, c26950_3, {
animated,
highlight: c26950_1 === scrollToMessageId2
});
}, 5);
} else {
NativeChatUtils.scrollTo(env18559[27].current, r59, {
animated,
highlight: jumpTargetId === scrollToMessageId2,
position: scrollPosition
});
}
}
}
}
};
env18559[41] = scrollToMessageId;
const updateRows = function updateRows(r4 = {}) {
const { forceRender = false, forceReload, updateMessageIds = new Set(), scrollToMessageId: scrollToMessageId3 = null, jumpTargetId = null, jumpType = JumpType.ANIMATED, focusTargetId = null, ignoreEmbedDescriptionCache = false, messagesNewlyLoaded = false, shouldInitialScroll = false, minimizeScrolling = false, isRescrolling = false } = r4;
let overrideScrollJumpType = r4.overrideScrollJumpType;
const { isAnimated = true, hasJumpedToOriginalPost = false } = r4;
const r38 = env18559[27];
if (r38.current != null) {
let env26952;
const r40 = env26952 = {
$parent: env18559
};
env26952[0] = forceRender;
env26952[1] = updateMessageIds;
env26952[2] = ignoreEmbedDescriptionCache;
const rows = env18559[4] != null ? env18559[5] != null ? env18559[6] ? TTITracker.firstRowGenerator.measure($mk107736(r40)) : null : null : null;
const r53 = env18559[28];
const current = r53.current;
const r55 = env18559[20];
const scrollPosition = r55 != null ? r55.startId === scrollToMessageId3 ? ChatScrollPosition.MIDDLE : void 0 : void 0;
L57: {
if (rows != null && rows.length > 0) {
const r103 = {
rows: env18559[0].getPreviousRows(),
scrollToMessageId: scrollToMessageId3,
jumpTargetId,
jumpType: null,
shouldInitialScroll: null,
animated: null,
scrollPosition: null,
focusTargetId: null
};
if (overrideScrollJumpType == null) {
overrideScrollJumpType = env18559[5].jumpType;
}
r103.jumpType = overrideScrollJumpType;
const current2 = r53.current;
r103.shouldInitialScroll = current2 ? shouldInitialScroll : !current2;
r103.animated = env18559[29].current;
r103.scrollPosition = scrollPosition;
r103.focusTargetId = focusTargetId;
const scrollData = computeScrollData(r103);
r53.current = true;
(0, env18559[31])({
rows,
hasMoreMessagesAfter: env18559[5].hasMoreAfter,
isLoadingAtTop: (0, env18559[32])(rows, env18559[30].current),
scrollData,
HACK_iOSForceAnimations: messagesNewlyLoaded,
forceReload,
isAnimated
});
if (current) {
break L57;
}
env18559[33].finish({
channelId: env18559[34],
areMessagesCached: env18559[35]
});
} else {
if (r53.current) {
const r66 = env18559[36];
if (r66.hasUpdates()) {
r66.tryFlush();
break L57;
}
}
if (!r53.current && (rows != null && rows.length === 0)) {
NativeChatUtils.fadeIn(r38.current);
} else if (scrollToMessageId3 != null && !(0, env18559[37])(hasJumpedToOriginalPost)) {
(0, env18559[41])({
scrollToMessageId: scrollToMessageId3,
jumpTargetId,
jumpType,
scrollPosition,
minimizeScrolling,
isRescrolling,
hasJumpedToOriginalPost
});
} else if (focusTargetId != null) {
const r84 = (0, env18559[38])(focusTargetId);
if (r84 != null) {
NativeChatUtils.focus(r38.current, r84);
}
}
}
}
if (r53.current && r53.current !== current && env18559[22]) {
setTimeout(() => (0, env18559[39])(), 100);
}
}
};
env18559[42] = updateRows;
return {
createRows: function createRows(a0) {
let env26948;
const r3 = env26948 = {
$parent: env18559
};
env26948[0] = a0.forceRender;
env26948[1] = a0.updateMessageIds;
env26948[2] = a0.ignoreEmbedDescriptionCache;
return env18559[4] != null ? env18559[5] != null ? env18559[6] ? TTITracker.firstRowGenerator.measure($mk107736(r3)) : null : null : null;
},
updateRows,
scrollToMessageId,
maybeRescrollToMessageId: function maybeRescrollToMessageId(a0) {
let env26949;
const r3 = env26949 = {
$parent: env18559
};
env26949[0] = a0;
let r5 = arguments[1];
if (r5 === void 0) {
r5 = false;
}
env26949[1] = r5;
let r8 = arguments[2];
if (r8 === void 0) {
r8 = JumpType.INSTANT;
}
env26949[2] = r8;
let r13 = arguments[3];
if (r13 === void 0) {
r13 = false;
}
env26949[3] = r13;
if (a0 != null) {
setTimeout($mk107737(r3), 50);
}
}
};
};