Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3502686
D5669.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
D5669.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D5669: [lib] Populate messageStore.threads from threadInfos before setMessageStoreMessages
Attached
Detach File
Event Timeline
Log In to Comment