From 6883e199ae87eb5287f576420f1eb02b55e8a321 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 23 Jun 2021 15:57:39 -0700 Subject: [PATCH] Ensure that messages are in redux when scrolling --- ts/views/conversation_view.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index ac69a1555909..a5869b914061 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -32,6 +32,7 @@ import { isOutgoing, isTapToView, } from '../state/selectors/message'; +import { getMessagesByConversation } from '../state/selectors/conversations'; import { ConversationDetailsMembershipList } from '../components/conversation/conversation-details/ConversationDetailsMembershipList'; import { showSafetyNumberChangeDialog } from '../shims/showSafetyNumberChangeDialog'; @@ -1144,7 +1145,20 @@ Whisper.ConversationView = Whisper.View.extend({ throw new Error(`scrollToMessage: failed to load message ${messageId}`); } - const isInMemory = Boolean(window.MessageController.getById(messageId)); + const state = window.reduxStore.getState(); + + let isInMemory = true; + + if (!window.MessageController.getById(messageId)) { + isInMemory = false; + } + + // Message might be in memory, but not in the redux anymore because + // we call `messageReset()` in `loadAndScroll()`. + const messagesByConversation = getMessagesByConversation(state)[model.id]; + if (!messagesByConversation?.messageIds.includes(messageId)) { + isInMemory = false; + } if (isInMemory) { const { scrollToMessage } = window.reduxActions.conversations;