Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3362020
D13122.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D13122.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
@@ -6,11 +6,13 @@
import type { RawMessageInfo } 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';
function useGetLatestMessageEdit(): (
messageID: string,
) => Promise<?RawMessageInfo> {
const { getRelatedMessages } = getConfig().sqliteAPI;
+ const messageStore = useSelector(state => state.messageStore);
return React.useCallback(
async (messageID: string) => {
const relatedDBMessages = await getRelatedMessages(messageID);
@@ -22,7 +24,31 @@
// since the results are sorted on time
const originalMessage = relatedMessages.pop();
if (!originalMessage) {
- return undefined;
+ // It is possible that this message isn't yet present in the DB but is
+ // already present in Redux store
+ const messageFromRedux = messageStore.messages[messageID];
+ if (!messageFromRedux) {
+ return undefined;
+ }
+ // Edits are only supported for text messages
+ if (messageFromRedux.type !== messageTypes.TEXT) {
+ return messageFromRedux;
+ }
+ for (const threadMessageID of messageStore.threads[
+ messageFromRedux.threadID
+ ].messageIDs) {
+ const message = messageStore.messages[threadMessageID];
+ if (
+ message.type === messageTypes.EDIT_MESSAGE &&
+ message.targetMessageID === messageID
+ ) {
+ return {
+ ...messageFromRedux,
+ text: message.text,
+ };
+ }
+ }
+ return messageFromRedux;
}
if (originalMessage.id !== messageID) {
@@ -50,7 +76,7 @@
return editedOriginalMessage;
},
- [getRelatedMessages],
+ [getRelatedMessages, messageStore.messages, messageStore.threads],
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 8:56 PM (21 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2580962
Default Alt Text
D13122.diff (2 KB)
Attached To
Mode
D13122: [lib] Check the store when searching for message edits
Attached
Detach File
Event Timeline
Log In to Comment