Files
discord-decomp/sources/modules/messages/native/hooks/useScrollHandlers.tsx
T
2026-07-27 16:20:00 +03:00

415 lines
25 KiB
TypeScript

/* Metro module 11346; source: modules/messages/native/hooks/useScrollHandlers.tsx; dependencies: [31, 7729, 3, 4559, 9764, 690, 9850, 9852, 6531, 2] */
function _fun86749(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#86749, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:6, offset: 0x01f9e6fc, size: 195 bytes, params: 8, frame: 19
const env0_0 = require;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importAll(31) /* metro dependency 31 */;
let value = require(7729) /* metro dependency 7729: useChatBottomManagerUIStore */;
const env0_4 = value.updateIsAtBottom;
const env0_5 = value.updateShouldShowJumpToPresentButton;
value = importDefault(3) /* metro dependency 3: Logger */;
value = new value('useScrollHandlers');
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/messages/native/hooks/useScrollHandlers.tsx');
exports.default = useScrollHandlers;
}
function useScrollHandlers({chatRef, chatManager, chatUpdatesQueue, pendingUpdatesQueueRef, animatedRef, fetchMoreBefore, fetchMoreAfter, handleVisibleMessagesChange, applyNativeRowsUpdate, messages, channel, channelId, screenIndex, onScroll, useReducedMotion, isStaff, visibleMessagesWindowHandler}) { // fn#86750, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:308, offset: 0x01f9e7bf, size: 445 bytes, params: 2, frame: 21
const binding = pendingUpdatesQueueRef;
return {hasHandledScrollRef: binding.useRef(false), isAtBottomRef: binding.useRef(false),
isNearBottomRef: binding.useRef(false), isNearTopRef: binding.useRef(false),
deceleratingRef: binding.useRef(false), draggingRef: binding.useRef(false),
firstIgnoredScrollEventTimestampRef: binding.useRef(undefined), loadMoreBefore: function() {
animatedRef.current = true;
fetchMoreBefore();
}, loadMoreAfter: function() {
animatedRef.current = true;
fetchMoreAfter();
}, scrollToTop: scrollToTop_86756, scrollToRelativeOffset: scrollToRelativeOffset_86757,
scrollToTopMessage: scrollToTopMessage_86758, updateNativeRows: updateNativeRows,
handleScrollCallbacks: handleScrollCallbacks, handleScroll: handleScroll,
handleScrollPosition: handleScrollPosition};
}
function handleScrollCallbacks({eventTimestamp, isAtBottom, isNearBottom, isNearTop, dragging, decelerating, isFirstMessageVisible}) { // fn#86753, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:837, owner: useScrollHandlers.handleScrollCallbacks, offset: 0x01f9e9b2, size: 436 bytes, params: 2, frame: 26
var r10;
var r5;
var loadingMore;
var value3;
var isScreenReaderEnabled;
var defaultImport;
isNearBottom = !(isNearBottom === undefined) && isNearBottom;
isNearTop = !(isNearTop === undefined) && isNearTop;
dragging = !(dragging === undefined) && dragging;
decelerating = !(decelerating === undefined) && decelerating;
isFirstMessageVisible = !(isFirstMessageVisible === undefined) && isFirstMessageVisible;
if (channel == null) {
return false;
}
if (messages.length !== 0) {
value3 = environment.__proto__;
isScreenReaderEnabled = (require(4559) /* metro dependency 4559: useIsScreenReaderEnabledNative */).getIsScreenReaderEnabled();
loadingMore = messages.loadingMore;
if (loadingMore) {
r5 = !loadingMore;
} else {
r10 = dragging || decelerating;
r10 = !r10 ? isScreenReaderEnabled : r10;
r5 = r10;
}
r5 = r5 && pendingUpdatesQueueRef.current.length === 0;
if (env0_21.current) {
if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearTop) {
if (messages.hasMoreBefore) {
if (r5) {
loadMoreBefore_86751();
} else if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
onScroll({isFirstMessageVisible: isFirstMessageVisible});
chatUpdatesQueue.tryFlush();
} else {
loadingMore = messages.loadingMore;
if (loadingMore) {
return false;
}
isScreenReaderEnabled = (require(4559) /* metro dependency 4559: useIsScreenReaderEnabledNative */).getIsScreenReaderEnabled();
loadingMore = messages.loadingMore;
if (loadingMore) {
r5 = !loadingMore;
} else {
r10 = dragging || decelerating;
r10 = !r10 ? isScreenReaderEnabled : r10;
r5 = r10;
}
r5 = r5 && pendingUpdatesQueueRef.current.length === 0;
if (env0_21.current) {
if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearTop) {
if (messages.hasMoreBefore) {
if (r5) {
loadMoreBefore_86751();
} else if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (env0_20.current) {
if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (isNearBottom) {
if (messages.hasMoreAfter) {
if (r5) {
loadMoreAfter_86752();
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
} else if (!(env0_19.current === isAtBottom && env0_18.current)) {
defaultImport = importDefault(9764) /* metro dependency 9764: DimensionActionCreators */;
defaultImport.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom ? 1 : 0, 1, 0);
env0_18.current = true;
}
onScroll({isFirstMessageVisible: isFirstMessageVisible});
chatUpdatesQueue.tryFlush();
}
return true;
}
function handleScroll({eventTimestamp, isAtBottom, isNearBottom, isNearTop, dragging, decelerating, shouldShowJumpToPresent, isFirstMessageVisible}) { // fn#86754, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:1361, owner: useScrollHandlers.handleScroll, offset: 0x01f9eb66, size: 249 bytes, params: 2, frame: 21
var environment;
var value;
isNearBottom = !(isNearBottom === undefined) && isNearBottom;
isNearTop = !(isNearTop === undefined) && isNearTop;
dragging = !(dragging === undefined) && dragging;
decelerating = !(decelerating === undefined) && decelerating;
shouldShowJumpToPresent = !(shouldShowJumpToPresent === undefined) && shouldShowJumpToPresent;
isFirstMessageVisible = !(isFirstMessageVisible === undefined) && isFirstMessageVisible;
if (handleScrollCallbacks({eventTimestamp: eventTimestamp, isAtBottom: isAtBottom, isNearBottom: isNearBottom,
isNearTop: isNearTop, dragging: dragging, decelerating: decelerating,
shouldShowJumpToPresent: shouldShowJumpToPresent, isFirstMessageVisible: isFirstMessageVisible})) {
env0_19.current = isAtBottom;
env0_20.current = isNearBottom;
env0_21.current = isNearTop;
env0_23.current = dragging;
env0_22.current = decelerating;
value = environment.__proto__;
value = require(690) /* metro dependency 690: ReactBatchUpdatesNative */;
value.batchUpdates(function() {
updateShouldShowJumpToPresentButton(channelId, screenIndex,
shouldShowJumpToPresent || messages.hasMoreAfter);
updateIsAtBottom(screenIndex, isAtBottom);
});
}
}
function useScrollHandlersScrollToTop() { // fn#86756, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:2020, owner: useScrollHandlers.scrollToTop, offset: 0x01f9eca2, size: 70 bytes, params: 1, frame: 16
let value = a0;
let r4 = !(value !== undefined) || value;
value = environment.__proto__;
value = importDefault(9850) /* metro dependency 9850: NativeChatUtils */;
const scrollToTop = value.scrollToTop;
const current = chatRef.current;
r4 = r4 && !useReducedMotion;
Reflect.apply(scrollToTop, value, [current, r4]);
}
function useScrollHandlersScrollToRelativeOffset(a0) { // fn#86757, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:2090, owner: useScrollHandlers.scrollToRelativeOffset, offset: 0x01f9ece8, size: 74 bytes, params: 2, frame: 17
let value = a1;
let r5 = !(value !== undefined) || value;
value = environment.__proto__;
value = importDefault(9850) /* metro dependency 9850: NativeChatUtils */;
const scrollToRelativeOffset = value.scrollToRelativeOffset;
const current = chatRef.current;
r5 = r5 && !useReducedMotion;
Reflect.apply(scrollToRelativeOffset, value, [current, a0, r5]);
}
function useScrollHandlersScrollToTopMessage() { // fn#86758, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:2171, owner: useScrollHandlers.scrollToTopMessage, offset: 0x01f9ed32, size: 90 bytes, params: 1, frame: 14
var value3;
var defaultImport;
const previousRows = chatManager.getPreviousRows();
if (previousRows.length > 0) {
value3 = environment.__proto__;
defaultImport = importDefault(9850) /* metro dependency 9850: NativeChatUtils */;
defaultImport.scrollTo(chatRef.current, previousRows.length - 1);
}
}
function updateNativeRows(a0) { // fn#86759, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:2271, owner: useScrollHandlers.updateNativeRows, offset: 0x01f9ed8c, size: 101 bytes, params: 2, frame: 12
if (chatUpdatesQueue.isBlocking) {
chatUpdatesQueue.add(a0);
} else if (a0.isLoadingAtTop) {
if (env0_22.current) {
chatUpdatesQueue.add(a0);
} else if (env0_23.current) {
chatUpdatesQueue.add(a0);
} else {
applyNativeRowsUpdate(a0);
}
} else {
applyNativeRowsUpdate(a0);
}
}
function useScrollHandlersHandleScrollPosition({timeStamp, nativeEvent}) { // fn#86760, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:11532:2444, owner: useScrollHandlers.handleScrollPosition, offset: 0x01f9edf1, size: 407 bytes, params: 2, frame: 32
var binding;
const isAtBottom = nativeEvent.isAtBottom;
const isNearBottom = nativeEvent.isNearBottom;
const isNearTop = nativeEvent.isNearTop;
const dragging = nativeEvent.dragging;
const decelerating = nativeEvent.decelerating;
const shouldShowJumpToPresent = nativeEvent.shouldShowJumpToPresent;
const isFirstMessageVisible = nativeEvent.isFirstMessageVisible;
const firstVisibleMessageIndex = nativeEvent.firstVisibleMessageIndex;
const firstVisibleMessagePercentVisible = nativeEvent.firstVisibleMessagePercentVisible;
const lastVisibleMessageIndex = nativeEvent.lastVisibleMessageIndex;
const changesetUpdateId = nativeEvent.changesetUpdateId;
const lastVisibleMessagePercentVisible = nativeEvent.lastVisibleMessagePercentVisible;
const changesetIdForChat = (require(9852) /* metro dependency 9852: ChatChangesetUpdateTracker */).getChangesetIdForChat(chatRef.current);
if (changesetUpdateId !== changesetIdForChat) {
if (env0_17.current == null) {
env0_17.current = timeStamp;
}
if (isStaff) {
binding = env1_6;
binding.log('STAFF-ACK-LOG: Ignoring outdated scroll event.', channelId, changesetUpdateId,
changesetIdForChat,
timeStamp);
}
} else {
var handleVisibleMessagesChangeBinding = handleVisibleMessagesChange;
var object2 = {firstVisibleMessageRowIndex: firstVisibleMessageIndex,
lastVisibleMessageRowIndex: lastVisibleMessageIndex,
firstVisibleMessagePercentVisible: firstVisibleMessagePercentVisible,
lastVisibleMessagePercentVisible: lastVisibleMessagePercentVisible};
var QuestsVisibleMessagesChangedSource = (require(6531) /* metro dependency 6531: QuestTypes */).QuestsVisibleMessagesChangedSource;
var SCROLL = QuestsVisibleMessagesChangedSource.SCROLL;
object2.source = SCROLL;
handleVisibleMessagesChangeBinding(object2);
var r17 = env0_17.current ?? timeStamp;
env0_17.current = undefined;
handleScroll({eventTimestamp: r17, isAtBottom: isAtBottom, isNearBottom: isNearBottom, isNearTop: isNearTop,
dragging: dragging, decelerating: decelerating, shouldShowJumpToPresent: shouldShowJumpToPresent,
isFirstMessageVisible: isFirstMessageVisible});
visibleMessagesWindowHandler.handleScrollPosition({rows: chatManager._rows,
firstVisibleMessageRowIndex: firstVisibleMessageIndex,
lastVisibleMessageRowIndex: lastVisibleMessageIndex});
}
}