Skip to content

Commit fcf32fe

Browse files
ConversationController: Send changes to redux only if conversation in lookups
1 parent 8b779b9 commit fcf32fe

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

ts/ConversationController.preload.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ export class ConversationController {
261261
conversation: ConversationModel,
262262
previousAttributes: ConversationAttributesType
263263
): void {
264+
if (!this.#_initialFetchComplete) {
265+
log.warn(
266+
`conversationChanged: Initial fetch is incomplete; ignoring change from ${conversation.idForLogging()}`
267+
);
268+
return;
269+
}
270+
271+
const existing = this.get(conversation.id);
272+
if (!existing) {
273+
log.warn(
274+
`conversationChanged: Rejecting change from ${conversation.idForLogging()}, not in lookups`
275+
);
276+
return;
277+
}
278+
264279
// eslint-disable-next-line no-param-reassign
265280
conversation.cachedProps = undefined;
266281

ts/state/ducks/conversations.preload.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,12 @@ function markConversationRead(
15371537
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
15381538
return async dispatch => {
15391539
const model = window.ConversationController.get(conversationId);
1540-
strictAssert(model, 'Conversation must be found');
1540+
if (!model) {
1541+
log.error(
1542+
'markConversationRead: Conversation not found, returning early'
1543+
);
1544+
return;
1545+
}
15411546
model.setMarkedUnread(false);
15421547

15431548
const lastMessage = await DataReader.getLastConversationMessage({
@@ -4865,7 +4870,10 @@ function onConversationOpened(
48654870
const promises: Array<Promise<void>> = [];
48664871
const conversation = window.ConversationController.get(conversationId);
48674872
if (!conversation) {
4868-
throw new Error('onConversationOpened: Conversation not found');
4873+
log.error(
4874+
`onConversationOpened: Conversation with id ${conversationId} not found`
4875+
);
4876+
return;
48694877
}
48704878

48714879
const logId = `onConversationOpened(${conversation.idForLogging()})`;

ts/state/selectors/conversations.dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ import { countAllChatFoldersMutedStats } from '../../util/countMutedStats.std.js
9292

9393
const { isNumber, pick } = lodash;
9494

95-
const log = createLogger('conversations');
95+
const log = createLogger('selectors/conversations');
9696

9797
export type ConversationWithStoriesType = ConversationType & {
9898
hasStories?: HasStories;

ts/state/smart/ChatsTab.preload.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// SPDX-License-Identifier: AGPL-3.0-only
33
import React, { memo, useEffect, useRef } from 'react';
44
import { useSelector } from 'react-redux';
5+
6+
import { createLogger } from '../../logging/log.std.js';
57
import { ChatsTab } from '../../components/ChatsTab.dom.js';
68
import type { SmartConversationViewProps } from './ConversationView.preload.js';
79
import { SmartConversationView } from './ConversationView.preload.js';
@@ -14,7 +16,6 @@ import { usePrevious } from '../../hooks/usePrevious.std.js';
1416
import { TargetedMessageSource } from '../ducks/conversationsEnums.std.js';
1517
import { useConversationsActions } from '../ducks/conversations.preload.js';
1618
import { useToastActions } from '../ducks/toast.preload.js';
17-
import { strictAssert } from '../../util/assert.std.js';
1819
import { isStagingServer } from '../../util/isStagingServer.dom.js';
1920
import { ToastType } from '../../types/Toast.dom.js';
2021
import { getNavTabsCollapsed } from '../selectors/items.dom.js';
@@ -28,6 +29,8 @@ import {
2829
getTargetedMessageSource,
2930
} from '../selectors/conversations.dom.js';
3031

32+
const log = createLogger('smart/ChatsTab');
33+
3134
function renderConversationView(props: SmartConversationViewProps) {
3235
return <SmartConversationView {...props} />;
3336
}
@@ -100,7 +103,10 @@ export const SmartChatsTab = memo(function SmartChatsTab() {
100103
const conversation = window.ConversationController.get(
101104
selectedConversationId
102105
);
103-
strictAssert(conversation, 'Conversation must be found');
106+
if (!conversation) {
107+
log.error('Conversation not found, returning early');
108+
return;
109+
}
104110
conversation.setMarkedUnread(false);
105111
}
106112
}, [prevConversationId, selectedConversationId]);

0 commit comments

Comments
 (0)