Ensure that messages are in redux when scrolling

This commit is contained in:
Fedor Indutny 2021-06-23 15:57:39 -07:00 committed by GitHub
parent dcb5bb6726
commit 6883e199ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,6 +32,7 @@ import {
isOutgoing, isOutgoing,
isTapToView, isTapToView,
} from '../state/selectors/message'; } from '../state/selectors/message';
import { getMessagesByConversation } from '../state/selectors/conversations';
import { ConversationDetailsMembershipList } from '../components/conversation/conversation-details/ConversationDetailsMembershipList'; import { ConversationDetailsMembershipList } from '../components/conversation/conversation-details/ConversationDetailsMembershipList';
import { showSafetyNumberChangeDialog } from '../shims/showSafetyNumberChangeDialog'; import { showSafetyNumberChangeDialog } from '../shims/showSafetyNumberChangeDialog';
@ -1144,7 +1145,20 @@ Whisper.ConversationView = Whisper.View.extend({
throw new Error(`scrollToMessage: failed to load message ${messageId}`); 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) { if (isInMemory) {
const { scrollToMessage } = window.reduxActions.conversations; const { scrollToMessage } = window.reduxActions.conversations;