Improve handling of invalid conversations

This commit is contained in:
trevor-signal 2023-05-19 09:28:59 -04:00 committed by GitHub
parent 4404429ec2
commit 36432b3a3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 6 deletions

View file

@ -5459,6 +5459,16 @@ export function reducer(
const { payload } = action;
const { conversationId, messageId, switchToAssociatedView } = payload;
let conversation: ConversationType | undefined;
if (conversationId) {
conversation = getOwn(state.conversationLookup, conversationId);
if (!conversation) {
log.error(`Unknown conversation selected, id: [${conversationId}]`);
return state;
}
}
const nextState = {
...omit(state, 'contactSpoofingReview'),
selectedConversationId: conversationId,
@ -5466,11 +5476,7 @@ export function reducer(
targetedMessageSource: TargetedMessageSource.NavigateToMessage,
};
if (switchToAssociatedView && conversationId) {
const conversation = getOwn(state.conversationLookup, conversationId);
if (!conversation) {
return nextState;
}
if (switchToAssociatedView && conversation) {
return {
...omit(nextState, 'composer', 'selectedMessageIds'),
showArchived: Boolean(conversation.isArchived),

View file

@ -372,7 +372,7 @@ describe('both/state/ducks/conversations', () => {
}
describe('showConversation', () => {
it('selects a conversation id', () => {
it('does not select a conversation if it does not exist', () => {
const state = {
...getEmptyState(),
};
@ -385,14 +385,44 @@ describe('both/state/ducks/conversations', () => {
const action = dispatch.getCall(0).args[0];
const nextState = reducer(state, action);
assert.isUndefined(nextState.selectedConversationId);
assert.isUndefined(nextState.targetedMessage);
});
it('selects a conversation id', () => {
const conversation = getDefaultConversation({
id: 'abc123',
});
const state = {
...getEmptyState(),
conversationLookup: {
[conversation.id]: conversation,
},
};
const dispatch = sinon.spy();
showConversation({ conversationId: 'abc123' })(
dispatch,
getEmptyRootState,
null
);
const action = dispatch.getCall(0).args[0];
const nextState = reducer(state, action);
assert.equal(nextState.selectedConversationId, 'abc123');
assert.isUndefined(nextState.targetedMessage);
});
it('selects a conversation and a message', () => {
const conversation = getDefaultConversation({
id: 'abc123',
});
const state = {
...getEmptyState(),
conversationLookup: {
[conversation.id]: conversation,
},
};
const dispatch = sinon.spy();
showConversation({
conversationId: 'abc123',