diff --git a/lib/shared/updates/update-thread-read-status-spec.js b/lib/shared/updates/update-thread-read-status-spec.js --- a/lib/shared/updates/update-thread-read-status-spec.js +++ b/lib/shared/updates/update-thread-read-status-spec.js @@ -4,8 +4,8 @@ import type { UpdateSpec } from './update-spec.js'; import type { - LegacyRawThreadInfo, - LegacyRawThreadInfos, + RawThreadInfo, + RawThreadInfos, } from '../../types/thread-types.js'; import { updateTypes } from '../../types/update-types-enum.js'; import type { @@ -21,33 +21,57 @@ ThreadReadStatusUpdateData, > = Object.freeze({ generateOpsForThreadUpdates( - storeThreadInfos: LegacyRawThreadInfos, + storeThreadInfos: RawThreadInfos, update: ThreadReadStatusUpdateInfo, ) { - const storeThreadInfo: ?LegacyRawThreadInfo = - storeThreadInfos[update.threadID]; if ( - !storeThreadInfo || - storeThreadInfo.currentUser.unread === update.unread + !storeThreadInfos[update.threadID] || + storeThreadInfos[update.threadID].currentUser.unread === update.unread ) { return null; } - const updatedThread = { - ...storeThreadInfo, - currentUser: { - ...storeThreadInfo.currentUser, + const storeThreadInfo: RawThreadInfo = storeThreadInfos[update.threadID]; + // TODO (atul): Try to get rid of this ridiculous branching. + if (storeThreadInfo.minimallyEncoded) { + const currentUser = storeThreadInfo.currentUser; + const updatedUser = { + role: currentUser.role, + subscription: currentUser.subscription, unread: update.unread, - }, - }; - return [ - { - type: 'replace', - payload: { - id: update.threadID, - threadInfo: updatedThread, + minimallyEncoded: true, + permissions: currentUser.permissions, + }; + const updatedThread = { + ...storeThreadInfo, + currentUser: updatedUser, + }; + return [ + { + type: 'replace', + payload: { + id: update.threadID, + threadInfo: updatedThread, + }, + }, + ]; + } else { + const updatedThread = { + ...storeThreadInfo, + currentUser: { + ...storeThreadInfo.currentUser, + unread: update.unread, }, - }, - ]; + }; + return [ + { + type: 'replace', + payload: { + id: update.threadID, + threadInfo: updatedThread, + }, + }, + ]; + } }, rawUpdateInfoFromRow(row: Object) { const { threadID, unread } = JSON.parse(row.content);