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 {