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 @@ -1,5 +1,6 @@ // @flow +import invariant from 'invariant'; import _groupBy from 'lodash/fp/groupBy.js'; import * as React from 'react'; import uuid from 'uuid'; @@ -207,8 +208,10 @@ const repliesCountIncreasingMessages = messagesByThreadID[ threadID ].filter(message => messageSpecs[message.type].includedInRepliesCount); + + const threadInfo = updatedThreadInfosByThreadID[threadID]; + if (repliesCountIncreasingMessages.length > 0) { - const threadInfo = updatedThreadInfosByThreadID[threadID]; const repliesCountIncreaseTime = Math.max( repliesCountIncreasingMessages.map(message => message.time), ); @@ -230,17 +233,52 @@ if (messagesFromOtherPeers.length === 0) { continue; } - // We take the most recent timestamp to make sure that updates older + // We take the most recent timestamp to make sure that + // change_thread_read_status operation older // than it won't flip the status to read. const time = Math.max( messagesFromOtherPeers.map(message => message.time), ); + invariant(threadInfo.thick, 'Thread should be thick'); + + // We aren't checking if the unread timestamp is lower than the time. + // We're doing this because we want to flip the thread to unread after + // any new message from a non-viewer. + const updatedThreadInfo = threadInfo.minimallyEncoded + ? { + ...threadInfo, + currentUser: { + ...threadInfo.currentUser, + unread: true, + }, + timestamps: { + ...threadInfo.timestamps, + currentUser: { + ...threadInfo.timestamps.currentUser, + unread: time, + }, + }, + } + : { + ...threadInfo, + currentUser: { + ...threadInfo.currentUser, + unread: true, + }, + timestamps: { + ...threadInfo.timestamps, + currentUser: { + ...threadInfo.timestamps.currentUser, + unread: time, + }, + }, + }; + updateInfos.push({ - type: updateTypes.UPDATE_THREAD_READ_STATUS, + type: updateTypes.UPDATE_THREAD, id: uuid.v4(), time, - threadID, - unread: true, + threadInfo: updatedThreadInfo, }); }