diff --git a/web/chat/chat-message-list.react.js b/web/chat/chat-message-list.react.js --- a/web/chat/chat-message-list.react.js +++ b/web/chat/chat-message-list.react.js @@ -11,6 +11,7 @@ fetchMessagesBeforeCursorActionTypes, fetchMessagesBeforeCursor, fetchMostRecentMessagesActionTypes, + fetchMostRecentMessages, } from 'lib/actions/message-actions'; import { registerFetchKey } from 'lib/reducers/loading-reducer'; import { @@ -66,6 +67,9 @@ threadID: string, beforeMessageID: string, ) => Promise, + +fetchMostRecentMessages: ( + threadID: string, + ) => Promise, // withInputState +inputState: ?InputState, }; @@ -346,6 +350,7 @@ if (!this.messageContainer) { return; } + const { scrollTop, scrollHeight, clientHeight } = this.messageContainer; if ( this.props.startReached || @@ -353,19 +358,23 @@ ) { return; } - const oldestMessageServerID = this.oldestMessageServerID(); - if (!oldestMessageServerID) { - return; - } + if (this.loadingFromScroll) { return; } this.loadingFromScroll = true; + const threadID = this.props.activeChatThreadID; invariant(threadID, 'should be set'); + + const oldestMessageServerID = this.oldestMessageServerID(); + const promise = oldestMessageServerID + ? this.props.fetchMessagesBeforeCursor(threadID, oldestMessageServerID) + : this.props.fetchMostRecentMessages(threadID); + this.props.dispatchActionPromise( fetchMessagesBeforeCursorActionTypes, - this.props.fetchMessagesBeforeCursor(threadID, oldestMessageServerID), + promise, ); } @@ -447,6 +456,7 @@ const callFetchMessagesBeforeCursor = useServerCall( fetchMessagesBeforeCursor, ); + const callFetchMostRecentMessages = useServerCall(fetchMostRecentMessages); const inputState = React.useContext(InputStateContext); const [dndProps, connectDropTarget] = useDrop({ @@ -485,6 +495,7 @@ inputState={inputState} dispatchActionPromise={dispatchActionPromise} fetchMessagesBeforeCursor={callFetchMessagesBeforeCursor} + fetchMostRecentMessages={callFetchMostRecentMessages} {...dndProps} connectDropTarget={connectDropTarget} />