Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2765537
D13059.id43338.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
D13059.id43338.diff
View Options
diff --git a/lib/shared/dm-ops/process-dm-ops.js b/lib/shared/dm-ops/process-dm-ops.js
--- a/lib/shared/dm-ops/process-dm-ops.js
+++ b/lib/shared/dm-ops/process-dm-ops.js
@@ -15,8 +15,13 @@
processDMOpsActionType,
queueDMOpsActionType,
} from '../../types/dm-ops.js';
+import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js';
+import { threadTypes } from '../../types/thread-types-enum.js';
+import type { LegacyRawThreadInfo } from '../../types/thread-types.js';
import { updateTypes } from '../../types/update-types-enum.js';
import { useSelector } from '../../utils/redux-utils.js';
+import { messageSpecs } from '../messages/message-specs.js';
+import { updateSpecs } from '../updates/update-specs.js';
function useProcessDMOperation(): (
dmOp: DMOperation,
@@ -72,7 +77,43 @@
const messagesByThreadID = _groupBy(message => message.threadID)(
allNewMessageInfos,
);
+
+ const updatedThickSidebars = updateInfos
+ .map(update => updateSpecs[update.type].getUpdatedThreadInfo?.(update))
+ .filter(thread => thread?.type === threadTypes.THICK_SIDEBAR);
+ const updatedThreadInfosByThreadID: {
+ [string]: RawThreadInfo | LegacyRawThreadInfo,
+ } = {};
+ for (const threadInfo of updatedThickSidebars) {
+ if (threadInfo?.id) {
+ // We can have multiple thread infos with the same ID, and we want
+ // to keep the last one.
+ updatedThreadInfosByThreadID[threadInfo.id] = threadInfo;
+ }
+ }
+
for (const threadID in messagesByThreadID) {
+ const repliesCountIncreasingMessages = messagesByThreadID[
+ threadID
+ ].filter(message => messageSpecs[message.type].includedInRepliesCount);
+ if (repliesCountIncreasingMessages.length > 0) {
+ const threadInfo =
+ updatedThreadInfosByThreadID[threadID] ?? threadInfos[threadID];
+ const repliesCountIncreaseTime = Math.max(
+ repliesCountIncreasingMessages.map(message => message.time),
+ );
+ updateInfos.push({
+ type: updateTypes.UPDATE_THREAD,
+ id: uuid.v4(),
+ time: repliesCountIncreaseTime,
+ threadInfo: {
+ ...threadInfo,
+ repliesCount:
+ threadInfo.repliesCount + repliesCountIncreasingMessages.length,
+ },
+ });
+ }
+
const messagesFromOtherPeers = messagesByThreadID[threadID].filter(
message => message.creatorID !== viewerID,
);
@@ -104,7 +145,7 @@
metadata,
);
},
- [viewerID, utilities, dispatchWithMessageSource],
+ [viewerID, utilities, dispatchWithMessageSource, threadInfos],
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Sep 20, 2:54 PM (21 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2150452
Default Alt Text
D13059.id43338.diff (2 KB)
Attached To
Mode
D13059: [lib] Update the replies count
Attached
Detach File
Event Timeline
Log In to Comment