Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3513783
D14137.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14137.diff
View Options
diff --git a/lib/hooks/latest-message-edit.js b/lib/hooks/latest-message-edit.js
--- a/lib/hooks/latest-message-edit.js
+++ b/lib/hooks/latest-message-edit.js
@@ -3,7 +3,7 @@
import * as React from 'react';
import { messageTypes } from '../types/message-types-enum.js';
-import type { RawMessageInfo } from '../types/message-types.js';
+import type { RawMessageInfo, MessageStore } from '../types/message-types.js';
import { getConfig } from '../utils/config.js';
import { translateClientDBMessageInfoToRawMessageInfo } from '../utils/message-ops-utils.js';
import { useSelector } from '../utils/redux-utils.js';
@@ -11,10 +11,21 @@
function useGetLatestMessageEdit(): (
messageID: string,
) => Promise<?RawMessageInfo> {
- const { getRelatedMessages } = getConfig().sqliteAPI;
const messageStore = useSelector(state => state.messageStore);
+ const baseGetLatestMessageEdit = useBaseGetLatestMessageEdit();
+ return React.useCallback(
+ (messageID: string) => baseGetLatestMessageEdit(messageID, messageStore),
+ [baseGetLatestMessageEdit, messageStore],
+ );
+}
+
+function useBaseGetLatestMessageEdit(): (
+ messageID: string,
+ messageStore: MessageStore,
+) => Promise<?RawMessageInfo> {
+ const { getRelatedMessages } = getConfig().sqliteAPI;
return React.useCallback(
- async (messageID: string) => {
+ async (messageID: string, messageStore: MessageStore) => {
const relatedDBMessages = await getRelatedMessages(messageID);
const relatedMessages = relatedDBMessages.map(
translateClientDBMessageInfoToRawMessageInfo,
@@ -76,8 +87,8 @@
return editedOriginalMessage;
},
- [getRelatedMessages, messageStore.messages, messageStore.threads],
+ [getRelatedMessages],
);
}
-export { useGetLatestMessageEdit };
+export { useGetLatestMessageEdit, useBaseGetLatestMessageEdit };
diff --git a/lib/hooks/thread-time.js b/lib/hooks/thread-time.js
--- a/lib/hooks/thread-time.js
+++ b/lib/hooks/thread-time.js
@@ -2,7 +2,7 @@
import * as React from 'react';
-import { useGetLatestMessageEdit } from './latest-message-edit.js';
+import { useBaseGetLatestMessageEdit } from './latest-message-edit.js';
import { messageSpecs } from '../shared/messages/message-specs.js';
import type {
MessageInfo,
@@ -19,7 +19,7 @@
messages: { +[id: string]: ?MessageInfo | RawMessageInfo },
) => LastUpdatedTimes {
const viewerID = useSelector(state => state.currentUserInfo?.id);
- const fetchMessage = useGetLatestMessageEdit();
+ const baseGetLatestMessageEdit = useBaseGetLatestMessageEdit();
return React.useCallback(
(threadInfo, messageStore, messages) => {
// This callback returns two variables:
@@ -47,7 +47,8 @@
const getLastUpdatedTimeParams = {
threadInfo,
viewerID,
- fetchMessage,
+ fetchMessage: (messageID: string) =>
+ baseGetLatestMessageEdit(messageID, messageStore),
};
let lastUpdatedTime: ?() => Promise<?number>;
@@ -126,7 +127,7 @@
lastUpdatedTime: lastUpdatedWithFallback,
};
},
- [viewerID, fetchMessage],
+ [viewerID, baseGetLatestMessageEdit],
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 2:04 AM (18 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2693161
Default Alt Text
D14137.diff (3 KB)
Attached To
Mode
D14137: [lib] Avoid unnecessary useSelector on MessageStore in useGetLastUpdatedTimes
Attached
Detach File
Event Timeline
Log In to Comment