Page MenuHomePhabricator

D13147.id43691.diff
No OneTemporary

D13147.id43691.diff

diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js
--- a/lib/shared/message-utils.js
+++ b/lib/shared/message-utils.js
@@ -10,9 +10,17 @@
import type { CreationSideEffectsFunc } from './messages/message-spec.js';
import { messageSpecs } from './messages/message-specs.js';
import { threadIsGroupChat } from './thread-utils.js';
+import {
+ fetchMessagesBeforeCursorActionTypes,
+ fetchMostRecentMessagesActionTypes,
+ useFetchMessagesBeforeCursor,
+ useFetchMostRecentMessages,
+} from '../actions/message-actions.js';
import { useStringForUser } from '../hooks/ens-cache.js';
+import { useOldestMessageServerID } from '../hooks/message-hooks.js';
import { extractKeyserverIDFromIDOptional } from '../keyserver-conn/keyserver-call-utils.js';
import { contentStringForMediaArray } from '../media/media-utils.js';
+import { registerFetchKey } from '../reducers/loading-reducer.js';
import type { ChatMessageInfoItem } from '../selectors/chat-selectors.js';
import { threadInfoSelector } from '../selectors/thread-selectors.js';
import { userIDsToRelativeUserInfos } from '../selectors/user-selectors.js';
@@ -45,6 +53,7 @@
ThreadInfo,
RawThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
+import { threadTypeIsThick } from '../types/thread-types-enum.js';
import type { LegacyRawThreadInfo } from '../types/thread-types.js';
import type { UserInfos } from '../types/user-types.js';
import {
@@ -52,6 +61,7 @@
ET,
useEntityTextAsString,
} from '../utils/entity-text.js';
+import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useSelector } from '../utils/redux-utils.js';
const localIDPrefix = 'local';
@@ -675,6 +685,46 @@
return timePerKeyserver;
}
+function useFetchMessages(threadInfo: ThreadInfo): () => Promise<void> {
+ const oldestMessageServerID = useOldestMessageServerID(threadInfo.id);
+ const callFetchMessagesBeforeCursor = useFetchMessagesBeforeCursor();
+ const callFetchMostRecentMessages = useFetchMostRecentMessages();
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ React.useEffect(() => {
+ registerFetchKey(fetchMessagesBeforeCursorActionTypes);
+ registerFetchKey(fetchMostRecentMessagesActionTypes);
+ }, []);
+
+ return React.useCallback(async () => {
+ const threadID = threadInfo.id;
+ if (threadTypeIsThick(threadInfo.type)) {
+ return;
+ }
+ if (oldestMessageServerID) {
+ await dispatchActionPromise(
+ fetchMessagesBeforeCursorActionTypes,
+ callFetchMessagesBeforeCursor({
+ threadID,
+ beforeMessageID: oldestMessageServerID,
+ }),
+ );
+ } else {
+ await dispatchActionPromise(
+ fetchMostRecentMessagesActionTypes,
+ callFetchMostRecentMessages({ threadID }),
+ );
+ }
+ }, [
+ callFetchMessagesBeforeCursor,
+ callFetchMostRecentMessages,
+ dispatchActionPromise,
+ oldestMessageServerID,
+ threadInfo.id,
+ threadInfo.type,
+ ]);
+}
+
export {
localIDPrefix,
messageKey,
@@ -708,4 +758,5 @@
isInvalidPinSourceForThread,
isUnableToBeRenderedIndependently,
findNewestMessageTimePerKeyserver,
+ useFetchMessages,
};
diff --git a/native/chat/message-list.react.js b/native/chat/message-list.react.js
--- a/native/chat/message-list.react.js
+++ b/native/chat/message-list.react.js
@@ -6,25 +6,10 @@
import { TouchableWithoutFeedback, View } from 'react-native';
import { createSelector } from 'reselect';
-import {
- fetchMessagesBeforeCursorActionTypes,
- type FetchMessagesBeforeCursorInput,
- fetchMostRecentMessagesActionTypes,
- type FetchMostRecentMessagesInput,
- useFetchMessagesBeforeCursor,
- useFetchMostRecentMessages,
-} from 'lib/actions/message-actions.js';
-import { useOldestMessageServerID } from 'lib/hooks/message-hooks.js';
-import { registerFetchKey } from 'lib/reducers/loading-reducer.js';
-import { messageKey } from 'lib/shared/message-utils.js';
+import { messageKey, useFetchMessages } from 'lib/shared/message-utils.js';
import { useWatchThread } from 'lib/shared/watch-thread-utils.js';
-import type { FetchMessageInfosPayload } from 'lib/types/message-types.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { threadTypes } from 'lib/types/thread-types-enum.js';
-import {
- type DispatchActionPromise,
- useDispatchActionPromise,
-} from 'lib/utils/redux-promise-utils.js';
import ChatList from './chat-list.react.js';
import type { ChatNavigationProp } from './chat.react.js';
@@ -78,16 +63,9 @@
+startReached: boolean,
+styles: $ReadOnly<typeof unboundStyles>,
+indicatorStyle: IndicatorStyle,
- +dispatchActionPromise: DispatchActionPromise,
- +fetchMessagesBeforeCursor: (
- input: FetchMessagesBeforeCursorInput,
- ) => Promise<FetchMessageInfosPayload>,
- +fetchMostRecentMessages: (
- input: FetchMostRecentMessagesInput,
- ) => Promise<FetchMessageInfosPayload>,
+overlayContext: ?OverlayContextType,
+keyboardState: ?KeyboardState,
- +oldestMessageServerID: ?string,
+ +fetchMessages: () => Promise<mixed>,
};
type State = {
+focusedMessageKey: ?string,
@@ -300,25 +278,10 @@
}
this.setState({ loadingFromScroll: true });
- const { oldestMessageServerID } = this.props;
- const threadID = this.props.threadInfo.id;
void (async () => {
try {
- if (oldestMessageServerID) {
- await this.props.dispatchActionPromise(
- fetchMessagesBeforeCursorActionTypes,
- this.props.fetchMessagesBeforeCursor({
- threadID,
- beforeMessageID: oldestMessageServerID,
- }),
- );
- } else {
- await this.props.dispatchActionPromise(
- fetchMostRecentMessagesActionTypes,
- this.props.fetchMostRecentMessages({ threadID }),
- );
- }
+ await this.props.fetchMessages();
} finally {
this.setState({ loadingFromScroll: false });
}
@@ -326,9 +289,6 @@
};
}
-registerFetchKey(fetchMessagesBeforeCursorActionTypes);
-registerFetchKey(fetchMostRecentMessagesActionTypes);
-
const ConnectedMessageList: React.ComponentType<BaseProps> =
React.memo<BaseProps>(function ConnectedMessageList(props: BaseProps) {
const keyboardState = React.useContext(KeyboardContext);
@@ -346,11 +306,7 @@
const styles = useStyles(unboundStyles);
const indicatorStyle = useIndicatorStyle();
- const dispatchActionPromise = useDispatchActionPromise();
- const callFetchMessagesBeforeCursor = useFetchMessagesBeforeCursor();
- const callFetchMostRecentMessages = useFetchMostRecentMessages();
-
- const oldestMessageServerID = useOldestMessageServerID(threadID);
+ const fetchMessages = useFetchMessages(props.threadInfo);
useWatchThread(props.threadInfo);
@@ -360,12 +316,9 @@
startReached={startReached}
styles={styles}
indicatorStyle={indicatorStyle}
- dispatchActionPromise={dispatchActionPromise}
- fetchMessagesBeforeCursor={callFetchMessagesBeforeCursor}
- fetchMostRecentMessages={callFetchMostRecentMessages}
overlayContext={overlayContext}
keyboardState={keyboardState}
- oldestMessageServerID={oldestMessageServerID}
+ fetchMessages={fetchMessages}
/>
);
});
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
@@ -6,35 +6,18 @@
import _debounce from 'lodash/debounce.js';
import * as React from 'react';
-import type {
- FetchMessagesBeforeCursorInput,
- FetchMostRecentMessagesInput,
-} from 'lib/actions/message-actions.js';
-import {
- fetchMessagesBeforeCursorActionTypes,
- fetchMostRecentMessagesActionTypes,
- useFetchMessagesBeforeCursor,
- useFetchMostRecentMessages,
-} from 'lib/actions/message-actions.js';
import { useThreadChatMentionCandidates } from 'lib/hooks/chat-mention-hooks.js';
-import { useOldestMessageServerID } from 'lib/hooks/message-hooks.js';
-import { registerFetchKey } from 'lib/reducers/loading-reducer.js';
import {
type ChatMessageItem,
useMessageListData,
} from 'lib/selectors/chat-selectors.js';
-import { messageKey } from 'lib/shared/message-utils.js';
+import { messageKey, useFetchMessages } from 'lib/shared/message-utils.js';
import {
threadIsPending,
threadOtherMembers,
} from 'lib/shared/thread-utils.js';
-import type { FetchMessageInfosPayload } from 'lib/types/message-types.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { threadTypes } from 'lib/types/thread-types-enum.js';
-import {
- type DispatchActionPromise,
- useDispatchActionPromise,
-} from 'lib/utils/redux-promise-utils.js';
import { defaultMaxTextAreaHeight, editBoxHeight } from './chat-constants.js';
import css from './chat-message-list.css';
@@ -66,20 +49,13 @@
+activeChatThreadID: ?string,
+messageListData: ?$ReadOnlyArray<ChatMessageItem>,
+startReached: boolean,
- +dispatchActionPromise: DispatchActionPromise,
- +fetchMessagesBeforeCursor: (
- input: FetchMessagesBeforeCursorInput,
- ) => Promise<FetchMessageInfosPayload>,
- +fetchMostRecentMessages: (
- input: FetchMostRecentMessagesInput,
- ) => Promise<FetchMessageInfosPayload>,
+inputState: ?InputState,
+clearTooltip: () => mixed,
- +oldestMessageServerID: ?string,
+isEditState: boolean,
+addScrollToMessageListener: ScrollToMessageCallback => mixed,
+removeScrollToMessageListener: ScrollToMessageCallback => mixed,
+viewerID: ?string,
+ +fetchMessages: () => Promise<mixed>,
};
type Snapshot = {
+scrollTop: number,
@@ -401,33 +377,14 @@
}
this.loadingFromScroll = true;
- const threadID = this.props.activeChatThreadID;
- invariant(threadID, 'should be set');
-
try {
- const { oldestMessageServerID } = this.props;
- if (oldestMessageServerID) {
- await this.props.dispatchActionPromise(
- fetchMessagesBeforeCursorActionTypes,
- this.props.fetchMessagesBeforeCursor({
- threadID,
- beforeMessageID: oldestMessageServerID,
- }),
- );
- } else {
- await this.props.dispatchActionPromise(
- fetchMostRecentMessagesActionTypes,
- this.props.fetchMostRecentMessages({ threadID }),
- );
- }
+ await this.props.fetchMessages();
} finally {
this.loadingFromScroll = false;
}
}
}
-registerFetchKey(fetchMessagesBeforeCursorActionTypes);
-registerFetchKey(fetchMostRecentMessagesActionTypes);
const ConnectedChatMessageList: React.ComponentType<BaseProps> =
React.memo<BaseProps>(function ConnectedChatMessageList(
props: BaseProps,
@@ -456,9 +413,7 @@
return threadMessageInfo.startReached;
});
- const dispatchActionPromise = useDispatchActionPromise();
- const callFetchMessagesBeforeCursor = useFetchMessagesBeforeCursor();
- const callFetchMostRecentMessages = useFetchMostRecentMessages();
+ const fetchMessages = useFetchMessages(threadInfo);
const inputState = React.useContext(InputStateContext);
@@ -476,8 +431,6 @@
return { getTextMessageMarkdownRules };
}, [getTextMessageMarkdownRules]);
- const oldestMessageServerID = useOldestMessageServerID(threadInfo.id);
-
const {
editState,
addScrollToMessageListener,
@@ -495,15 +448,12 @@
messageListData={messageListData}
startReached={startReached}
inputState={inputState}
- dispatchActionPromise={dispatchActionPromise}
- fetchMessagesBeforeCursor={callFetchMessagesBeforeCursor}
- fetchMostRecentMessages={callFetchMostRecentMessages}
clearTooltip={clearTooltip}
- oldestMessageServerID={oldestMessageServerID}
isEditState={isEditState}
addScrollToMessageListener={addScrollToMessageListener}
removeScrollToMessageListener={removeScrollToMessageListener}
viewerID={viewerID}
+ fetchMessages={fetchMessages}
/>
</MessageListContext.Provider>
);

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 9:08 AM (19 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2534432
Default Alt Text
D13147.id43691.diff (12 KB)

Event Timeline