Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3380835
D12358.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D12358.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
@@ -10,6 +10,7 @@
import _mapValues from 'lodash/fp/mapValues.js';
import _omit from 'lodash/fp/omit.js';
import _omitBy from 'lodash/fp/omitBy.js';
+import _pick from 'lodash/fp/pick.js';
import _pickBy from 'lodash/fp/pickBy.js';
import _uniq from 'lodash/fp/uniq.js';
@@ -195,6 +196,9 @@
{
type: 'remove_all_threads',
},
+ {
+ type: 'remove_all_local_message_infos',
+ },
{
type: 'replace_threads',
payload: { threads },
@@ -331,6 +335,7 @@
...messageStoreUpdatedWithLatestThreadInfos,
messages: messageStoreAfterUpdateOps.messages,
threads: messageStoreAfterUpdateOps.threads,
+ local: messageStoreAfterUpdateOps.local,
};
const localIDsToServerIDs: Map<string, string> = new Map();
@@ -464,7 +469,6 @@
);
const oldMessageInfosToCombine = [];
const threadsThatNeedMessageIDsResorted = [];
- const local: { [string]: LocalMessageInfo } = {};
const updatedThreads: { [string]: ThreadMessageInfo } = {};
const threads = _flow(
_mapValuesWithKeys((messageIDs: string[], threadID: string) => {
@@ -509,7 +513,13 @@
oldMessageInfosToCombine.push(oldMessageInfo);
const localInfo = updatedMessageStore.local[id];
if (localInfo) {
- local[id] = localInfo;
+ newMessageOps.push({
+ type: 'replace_local_message_info',
+ payload: {
+ id,
+ localMessageInfo: localInfo,
+ },
+ });
}
}
const startReached =
@@ -557,7 +567,13 @@
}
const localInfo = updatedMessageStore.local[id];
if (localInfo) {
- local[id] = localInfo;
+ newMessageOps.push({
+ type: 'replace_local_message_info',
+ payload: {
+ id,
+ localMessageInfo: localInfo,
+ },
+ });
}
}
}
@@ -615,7 +631,7 @@
const messageStore = {
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
- local,
+ local: processedMessageStore.local,
currentAsOf: {
...processedMessageStore.currentAsOf,
...currentAsOf,
@@ -692,6 +708,14 @@
payload: { threadIDs: threadsToRemoveMessagesFrom },
});
+ const localMessagesToRemove = _pick(messageIDsToRemove)(
+ reassignedMessageStore.local,
+ );
+ messageStoreOperations.push({
+ type: 'remove_local_message_infos',
+ payload: { ids: Object.keys(localMessagesToRemove) },
+ });
+
return {
messageStoreOperations,
messageStore: {
@@ -769,6 +793,7 @@
...freshStore,
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
+ local: processedMessageStore.local,
},
};
} else if (action.type === keyserverAuthActionTypes.success) {
@@ -905,6 +930,7 @@
currentAsOf,
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
+ local: processedMessageStore.local,
},
};
} else if (
@@ -926,6 +952,7 @@
...filteredMessageStore,
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
+ local: processedMessageStore.local,
},
};
} else if (action.type === newThreadActionTypes.success) {
@@ -1042,15 +1069,11 @@
];
let updatedThreads;
- let local = { ...messageStore.local };
if (messageStore.messages[localID]) {
const messages = {
...messageStore.messages,
[(localID: string)]: payload,
};
- local = _pickBy(
- (localInfo: LocalMessageInfo, key: string) => key !== localID,
- )(messageStore.local);
const thread = messageStore.threads[threadID];
updatedThreads = {
[(threadID: string)]: {
@@ -1058,6 +1081,13 @@
startReached: thread?.startReached ?? true,
},
};
+
+ messageStoreOperations.push({
+ type: 'remove_local_message_infos',
+ payload: {
+ ids: [localID],
+ },
+ });
} else {
updatedThreads = {
[(threadID: string)]: messageStore.threads[threadID]
@@ -1087,7 +1117,7 @@
const newMessageStore = {
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
- local,
+ local: processedMessageStore.local,
currentAsOf: messageStore.currentAsOf,
};
@@ -1100,15 +1130,30 @@
action.type === sendMultimediaMessageActionTypes.failed
) {
const { localID } = action.payload;
+
+ const messageStoreOperations = [
+ {
+ type: 'replace_local_message_info',
+ payload: {
+ id: localID,
+ localMessageInfo: {
+ sendFailed: true,
+ },
+ },
+ },
+ ];
+
+ const processedMessageStore = processMessageStoreOperations(
+ messageStore,
+ messageStoreOperations,
+ );
+
return {
- messageStoreOperations: [],
+ messageStoreOperations,
messageStore: {
- messages: messageStore.messages,
- threads: messageStore.threads,
- local: {
- ...messageStore.local,
- [(localID: string)]: { sendFailed: true },
- },
+ messages: processedMessageStore.messages,
+ threads: processedMessageStore.threads,
+ local: processedMessageStore.local,
currentAsOf: messageStore.currentAsOf,
},
};
@@ -1201,9 +1246,13 @@
_uniq,
sortMessageIDs(newMessages),
)(messageStore.threads[threadID].messageIDs.map(replaceMessageKey));
- const local = _pickBy(
- (localInfo: LocalMessageInfo, key: string) => key !== payload.localID,
- )(messageStore.local);
+
+ messageStoreOperations.push({
+ type: 'remove_local_message_infos',
+ payload: {
+ ids: [payload.localID],
+ },
+ });
const updatedThreads = {
[threadID]: {
@@ -1227,7 +1276,7 @@
...messageStore,
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
- local,
+ local: processedMessageStore.local,
},
};
} else if (action.type === saveMessagesActionType) {
@@ -1280,6 +1329,10 @@
updatedThreads[threadID] = thread;
}
+ const localMessageIDsToRemove = _pick(messageIDsToPrune)(
+ messageStore.local,
+ );
+
const messageStoreOperations = [
{
type: 'remove',
@@ -1291,6 +1344,10 @@
threads: updatedThreads,
},
},
+ {
+ type: 'remove_local_message_infos',
+ payload: { ids: Object.keys(localMessageIDsToRemove) },
+ },
];
const processedMessageStore = processMessageStoreOperations(
@@ -1301,7 +1358,7 @@
const newMessageStore = {
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
- local: _omit(messageIDsToPrune)(messageStore.local),
+ local: processedMessageStore.local,
currentAsOf: messageStore.currentAsOf,
};
@@ -1523,6 +1580,8 @@
messageStore: {
...messageStore,
messages: processedMessageStore.messages,
+ threads: processedMessageStore.threads,
+ local: processedMessageStore.local,
},
};
} else if (action.type === createLocalMessageActionType) {
@@ -1568,6 +1627,7 @@
...messageStore,
threads: processedMessageStore.threads,
messages: processedMessageStore.messages,
+ local: processedMessageStore.local,
},
};
} else if (action.type === processServerRequestsActionType) {
@@ -1587,6 +1647,7 @@
...messageStoreAfterReassignment,
messages: processedMessageStore.messages,
threads: processedMessageStore.threads,
+ local: processedMessageStore.local,
},
};
} else if (action.type === setClientDBStoreActionType) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 2:39 AM (21 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595492
Default Alt Text
D12358.diff (7 KB)
Attached To
Mode
D12358: [lib] update message reducer to use ops approach for local field
Attached
Detach File
Event Timeline
Log In to Comment