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 { @@ -62,6 +63,9 @@ threadID: string, beforeMessageID: string, ) => Promise, + +fetchMostRecentMessages: ( + threadID: string, + ) => Promise, // withInputState +inputState: ?InputState, }; @@ -341,6 +345,7 @@ if (!this.messageContainer) { return; } + const { scrollTop, scrollHeight, clientHeight } = this.messageContainer; if ( this.props.startReached || @@ -348,20 +353,27 @@ ) { 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'); - this.props.dispatchActionPromise( - fetchMessagesBeforeCursorActionTypes, - this.props.fetchMessagesBeforeCursor(threadID, oldestMessageServerID), - ); + + const oldestMessageServerID = this.oldestMessageServerID(); + if (oldestMessageServerID) { + this.props.dispatchActionPromise( + fetchMessagesBeforeCursorActionTypes, + this.props.fetchMessagesBeforeCursor(threadID, oldestMessageServerID), + ); + } else { + this.props.dispatchActionPromise( + fetchMostRecentMessagesActionTypes, + this.props.fetchMostRecentMessages(threadID), + ); + } } oldestMessageServerID(): ?string { @@ -441,6 +453,7 @@ const callFetchMessagesBeforeCursor = useServerCall( fetchMessagesBeforeCursor, ); + const callFetchMostRecentMessages = useServerCall(fetchMostRecentMessages); const inputState = React.useContext(InputStateContext); const [dndProps, connectDropTarget] = useDrop({ @@ -478,6 +491,7 @@ inputState={inputState} dispatchActionPromise={dispatchActionPromise} fetchMessagesBeforeCursor={callFetchMessagesBeforeCursor} + fetchMostRecentMessages={callFetchMostRecentMessages} {...dndProps} connectDropTarget={connectDropTarget} />