Page MenuHomePhabricator

D5669.diff
No OneTemporary

D5669.diff

diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js
--- a/lib/reducers/message-reducer.js
+++ b/lib/reducers/message-reducer.js
@@ -187,9 +187,9 @@
}
type ReassignmentResult = {
- +messageStoreOperations: $ReadOnlyArray<MessageStoreOperation>,
+ +messageStoreOperations: MessageStoreOperation[],
+messageStore: MessageStore,
- +reassignedThreadIDs: $ReadOnlyArray<string>,
+ +reassignedThreadIDs: string[],
};
function reassignMessagesToRealizedThreads(
@@ -569,9 +569,9 @@
}
type UpdateMessageStoreWithLatestThreadInfosResult = {
- +messageStoreOperations: $ReadOnlyArray<MessageStoreOperation>,
+ +messageStoreOperations: MessageStoreOperation[],
+messageStore: MessageStore,
- +reassignedThreadIDs: $ReadOnlyArray<string>,
+ +reassignedThreadIDs: string[],
};
function updateMessageStoreWithLatestThreadInfos(
messageStore: MessageStore,
@@ -1295,8 +1295,13 @@
},
};
} else if (action.type === setMessageStoreMessages) {
- let threads = { ...messageStore.threads };
- let local = { ...messageStore.local };
+ const {
+ messageStoreOperations,
+ messageStore: updatedMessageStore,
+ } = updateMessageStoreWithLatestThreadInfos(messageStore, newThreadInfos);
+
+ let threads = { ...updatedMessageStore.threads };
+ let local = { ...updatedMessageStore.local };
// Store message IDs already contained within threads so that we
// do not insert duplicates
@@ -1353,35 +1358,28 @@
);
}
- messageStore = {
- ...messageStore,
+ const newMessageStore = {
+ ...updatedMessageStore,
messages: actionPayloadMessages,
threads: threads,
local: local,
};
- if (messageIDsToBeRemoved.length === 0) {
- return { messageStoreOperations: [], messageStore };
- }
-
- const messageStoreOperations: MessageStoreOperation[] = [
- {
+ if (messageIDsToBeRemoved.length > 0) {
+ messageStoreOperations.push({
type: 'remove',
payload: { ids: messageIDsToBeRemoved },
- },
- ];
+ });
+ }
const processedMessageStore = processMessageStoreOperations(
- messageStore,
+ newMessageStore,
messageStoreOperations,
);
return {
messageStoreOperations,
- messageStore: {
- ...messageStore,
- messages: processedMessageStore.messages,
- },
+ messageStore: processedMessageStore,
};
}
return { messageStoreOperations: [], messageStore };
diff --git a/lib/reducers/message-reducer.test.js b/lib/reducers/message-reducer.test.js
--- a/lib/reducers/message-reducer.test.js
+++ b/lib/reducers/message-reducer.test.js
@@ -2,8 +2,10 @@
import invariant from 'invariant';
+import { createPendingThread } from '../shared/thread-utils';
import type { MessageStore } from '../types/message-types';
import { messageTypes } from '../types/message-types';
+import { threadTypes } from '../types/thread-types';
import { reduceMessageStore } from './message-reducer';
const messageStoreBeforeMediaUpdate: MessageStore = {
@@ -289,7 +291,12 @@
type: 'SET_MESSAGE_STORE_MESSAGES',
payload: clientDBMessages,
},
- {},
+ {
+ [88471]: createPendingThread({
+ viewerID: '',
+ threadType: threadTypes.LOCAL,
+ }),
+ },
);
test('removes local media when constructing messageStore.messages', () => {
expect(updatedMessageStore.messages).toHaveProperty('103502');

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 4:48 AM (18 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2685944
Default Alt Text
D5669.diff (3 KB)

Event Timeline