Page MenuHomePhabricator

D13122.diff
No OneTemporary

D13122.diff

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

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)

Event Timeline