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 @@ -67,6 +67,7 @@ sortMessageIDs, mergeThreadMessageInfos, findNewestMessageTimePerKeyserver, + localIDPrefix, } from '../shared/message-utils.js'; import { threadHasPermission, @@ -76,6 +77,7 @@ import threadWatcher from '../shared/thread-watcher.js'; import { unshimMessageInfos } from '../shared/unshim-utils.js'; import { updateSpecs } from '../shared/updates/update-specs.js'; +import { logInActionSources } from '../types/account-types.js'; import type { Media, Image } from '../types/media-types.js'; import { messageTypes } from '../types/message-types-enum.js'; import { @@ -726,10 +728,27 @@ action.type === logInActionTypes.success || action.type === siweAuthActionTypes.success ) { - const messagesResult = action.payload.messagesResult; + const { messagesResult } = action.payload; + let { messageInfos } = messagesResult; + + // If it's a resolution attempt and the userID doesn't change, + // then we should keep all local messages in the store + // TODO we can't check if the userID changed until ENG-6126 + if ( + action.payload.logInActionSource === + logInActionSources.cookieInvalidationResolutionAttempt || + action.payload.logInActionSource === + logInActionSources.socketAuthErrorResolutionAttempt + ) { + const localMessages = Object.values(messageStore.messages).filter( + rawMessageInfo => messageID(rawMessageInfo).startsWith(localIDPrefix), + ); + messageInfos = [...messageInfos, ...localMessages]; + } + const { messageStoreOperations, messageStore: freshStore } = freshMessageStore( - messagesResult.messageInfos, + messageInfos, messagesResult.truncationStatus, messagesResult.currentAsOf, newThreadInfos,