diff --git a/ts/ConversationController.preload.ts b/ts/ConversationController.preload.ts index 1e047634ed..3f103fca4b 100644 --- a/ts/ConversationController.preload.ts +++ b/ts/ConversationController.preload.ts @@ -261,6 +261,21 @@ export class ConversationController { conversation: ConversationModel, previousAttributes: ConversationAttributesType ): void { + if (!this.#_initialFetchComplete) { + log.warn( + `conversationChanged: Initial fetch is incomplete; ignoring change from ${conversation.idForLogging()}` + ); + return; + } + + const existing = this.get(conversation.id); + if (!existing) { + log.warn( + `conversationChanged: Rejecting change from ${conversation.idForLogging()}, not in lookups` + ); + return; + } + // eslint-disable-next-line no-param-reassign conversation.cachedProps = undefined; diff --git a/ts/state/ducks/conversations.preload.ts b/ts/state/ducks/conversations.preload.ts index 09c8519159..78beeb9f77 100644 --- a/ts/state/ducks/conversations.preload.ts +++ b/ts/state/ducks/conversations.preload.ts @@ -1537,7 +1537,12 @@ function markConversationRead( ): ThunkAction { return async dispatch => { const model = window.ConversationController.get(conversationId); - strictAssert(model, 'Conversation must be found'); + if (!model) { + log.error( + 'markConversationRead: Conversation not found, returning early' + ); + return; + } model.setMarkedUnread(false); const lastMessage = await DataReader.getLastConversationMessage({ @@ -4865,7 +4870,10 @@ function onConversationOpened( const promises: Array> = []; const conversation = window.ConversationController.get(conversationId); if (!conversation) { - throw new Error('onConversationOpened: Conversation not found'); + log.error( + `onConversationOpened: Conversation with id ${conversationId} not found` + ); + return; } const logId = `onConversationOpened(${conversation.idForLogging()})`; diff --git a/ts/state/selectors/conversations.dom.ts b/ts/state/selectors/conversations.dom.ts index a48532fec8..2a5ce58688 100644 --- a/ts/state/selectors/conversations.dom.ts +++ b/ts/state/selectors/conversations.dom.ts @@ -92,7 +92,7 @@ import { countAllChatFoldersMutedStats } from '../../util/countMutedStats.std.js const { isNumber, pick } = lodash; -const log = createLogger('conversations'); +const log = createLogger('selectors/conversations'); export type ConversationWithStoriesType = ConversationType & { hasStories?: HasStories; diff --git a/ts/state/smart/ChatsTab.preload.tsx b/ts/state/smart/ChatsTab.preload.tsx index e9a3f8dd9c..707a151848 100644 --- a/ts/state/smart/ChatsTab.preload.tsx +++ b/ts/state/smart/ChatsTab.preload.tsx @@ -2,6 +2,8 @@ // SPDX-License-Identifier: AGPL-3.0-only import React, { memo, useEffect, useRef } from 'react'; import { useSelector } from 'react-redux'; + +import { createLogger } from '../../logging/log.std.js'; import { ChatsTab } from '../../components/ChatsTab.dom.js'; import type { SmartConversationViewProps } from './ConversationView.preload.js'; import { SmartConversationView } from './ConversationView.preload.js'; @@ -14,7 +16,6 @@ import { usePrevious } from '../../hooks/usePrevious.std.js'; import { TargetedMessageSource } from '../ducks/conversationsEnums.std.js'; import { useConversationsActions } from '../ducks/conversations.preload.js'; import { useToastActions } from '../ducks/toast.preload.js'; -import { strictAssert } from '../../util/assert.std.js'; import { isStagingServer } from '../../util/isStagingServer.dom.js'; import { ToastType } from '../../types/Toast.dom.js'; import { getNavTabsCollapsed } from '../selectors/items.dom.js'; @@ -28,6 +29,8 @@ import { getTargetedMessageSource, } from '../selectors/conversations.dom.js'; +const log = createLogger('smart/ChatsTab'); + function renderConversationView(props: SmartConversationViewProps) { return ; } @@ -100,7 +103,10 @@ export const SmartChatsTab = memo(function SmartChatsTab() { const conversation = window.ConversationController.get( selectedConversationId ); - strictAssert(conversation, 'Conversation must be found'); + if (!conversation) { + log.error('Conversation not found, returning early'); + return; + } conversation.setMarkedUnread(false); } }, [prevConversationId, selectedConversationId]);