Page MenuHomePhabricator

D13059.id43338.diff
No OneTemporary

D13059.id43338.diff

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

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)

Event Timeline