diff --git a/lib/shared/dm-ops/change-thread-read-status-spec.js b/lib/shared/dm-ops/change-thread-read-status-spec.js --- a/lib/shared/dm-ops/change-thread-read-status-spec.js +++ b/lib/shared/dm-ops/change-thread-read-status-spec.js @@ -1,5 +1,6 @@ // @flow +import invariant from 'invariant'; import uuid from 'uuid'; import type { @@ -22,15 +23,39 @@ }, processDMOperation: async ( dmOperation: DMChangeThreadReadStatusOperation, + viewerID: string, + utilities: ProcessDMOperationUtilities, ) => { const { threadID, unread, time } = dmOperation; + + const threadInfo = utilities.threadInfos[threadID]; + invariant(threadInfo.thick, 'Thread should be thick'); + if (threadInfo.timestamps.currentUser.unread > time) { + return { + rawMessageInfos: [], + updateInfos: [], + }; + } + const updateInfos = [ { - type: updateTypes.UPDATE_THREAD_READ_STATUS, + type: updateTypes.UPDATE_THREAD, id: uuid.v4(), time, - threadID, - unread, + threadInfo: { + ...threadInfo, + currentUser: { + ...threadInfo.currentUser, + unread, + }, + timestamps: { + ...threadInfo.timestamps, + currentUser: { + ...threadInfo.timestamps.currentUser, + unread: time, + }, + }, + }, }, ]; return { 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 @@ -31,7 +31,6 @@ import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js'; import type { DispatchMetadata } from '../../types/redux-types.js'; import type { OutboundP2PMessage } from '../../types/sqlite-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 { extractUserIDsFromPayload } from '../../utils/conversion-utils.js'; @@ -194,10 +193,7 @@ const updatedThreadInfo = updateSpecs[ update.type ].getUpdatedThreadInfo?.(update, updatedThreadInfosByThreadID); - if ( - updatedThreadInfo && - updatedThreadInfo?.type === threadTypes.THICK_SIDEBAR - ) { + if (updatedThreadInfo) { updatedThreadInfosByThreadID[updatedThreadInfo.id] = updatedThreadInfo; }