diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js --- a/lib/reducers/message-reducer.js +++ b/lib/reducers/message-reducer.js @@ -63,6 +63,7 @@ sortMessageInfoList, sortMessageIDs, mergeThreadMessageInfos, + findNewestMessageTimePerKeyserver, } from '../shared/message-utils.js'; import { threadHasPermission, @@ -100,7 +101,6 @@ } from '../types/update-types.js'; import { setNewSessionActionType } from '../utils/action-utils.js'; import { translateClientDBThreadMessageInfos } from '../utils/message-ops-utils.js'; -import { ashoatKeyserverID } from '../utils/validation-utils.js'; const _mapValuesWithKeys = _mapValues.convert({ cap: false }); @@ -580,11 +580,6 @@ updatedThreads[threadID] = threads[threadID]; } - const currentAsOf = Math.max( - orderedNewMessageInfos.length > 0 ? orderedNewMessageInfos[0].time : 0, - updatedMessageStore.currentAsOf[ashoatKeyserverID], - ); - newMessageOps.push({ type: 'replace_threads', payload: { @@ -597,13 +592,24 @@ newMessageOps, ); + const currentAsOf = {}; + const newestMessageTimePerKeyserver = findNewestMessageTimePerKeyserver( + orderedNewMessageInfos, + ); + for (const keyserverID in newestMessageTimePerKeyserver) { + currentAsOf[keyserverID] = Math.max( + newestMessageTimePerKeyserver[keyserverID], + processedMessageStore.currentAsOf[keyserverID], + ); + } + const messageStore = { messages: processedMessageStore.messages, threads: processedMessageStore.threads, local, currentAsOf: { ...processedMessageStore.currentAsOf, - [ashoatKeyserverID]: currentAsOf, + ...currentAsOf, }, };