diff --git a/lib/shared/dm-ops/change-thread-settings-spec.js b/lib/shared/dm-ops/change-thread-settings-spec.js --- a/lib/shared/dm-ops/change-thread-settings-spec.js +++ b/lib/shared/dm-ops/change-thread-settings-spec.js @@ -14,7 +14,10 @@ import type { MessageData, RawMessageInfo } from '../../types/message-types'; import { messageTypes } from '../../types/message-types-enum.js'; import type { ChangeSettingsMessageData } from '../../types/messages/change-settings.js'; -import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js'; +import type { + RawThreadInfo, + ThickRawThreadInfo, +} from '../../types/minimally-encoded-thread-permissions-types.js'; import { updateTypes } from '../../types/update-types-enum.js'; import type { ClientUpdateInfo } from '../../types/update-types.js'; import { values } from '../../utils/objects.js'; @@ -100,11 +103,10 @@ const { time, messageIDsPrefix } = dmOperation; const threadID = getThreadIDFromChangeThreadSettingsDMOp(dmOperation); - let threadInfoToUpdate: ?RawThreadInfo = utilities.threadInfos[threadID]; + const threadInfo: ?RawThreadInfo = utilities.threadInfos[threadID]; const updateInfos: Array = []; const rawMessageInfos: Array = []; - invariant(threadInfoToUpdate?.thick, 'Thread should be thick'); const { fieldNameToMessageData, threadInfoUpdate } = createChangeSettingsMessageDatasAndUpdate(dmOperation); @@ -120,10 +122,21 @@ ), ); - threadInfoToUpdate = { - ...threadInfoToUpdate, - ...threadInfoUpdate, - }; + invariant(threadInfo?.thick, 'Thread should be thick'); + let threadInfoToUpdate: ThickRawThreadInfo = threadInfo; + for (const fieldName in threadInfoUpdate) { + const timestamp = threadInfoToUpdate.timestamps[fieldName]; + if (timestamp < time) { + threadInfoToUpdate = { + ...threadInfoToUpdate, + [fieldName]: threadInfoUpdate[fieldName], + timestamps: { + ...threadInfoToUpdate.timestamps, + [fieldName]: time, + }, + }; + } + } if (fieldNameToMessageDataPairs.length > 0) { updateInfos.push({