Do not fire SELECTED_CONVERSATION_CHANGED more than once
This commit is contained in:
parent
569b6e14a6
commit
74abe0c1ef
2 changed files with 56 additions and 28 deletions
|
@ -1057,16 +1057,23 @@ function onArchive(
|
|||
}
|
||||
function onUndoArchive(
|
||||
conversationId: string
|
||||
): SelectedConversationChangedActionType {
|
||||
const conversation = window.ConversationController.get(conversationId);
|
||||
if (!conversation) {
|
||||
throw new Error('onUndoArchive: Conversation not found!');
|
||||
}
|
||||
): ThunkAction<
|
||||
void,
|
||||
RootStateType,
|
||||
unknown,
|
||||
SelectedConversationChangedActionType
|
||||
> {
|
||||
return (dispatch, getState) => {
|
||||
const conversation = window.ConversationController.get(conversationId);
|
||||
if (!conversation) {
|
||||
throw new Error('onUndoArchive: Conversation not found!');
|
||||
}
|
||||
|
||||
conversation.setArchived(false);
|
||||
return showConversation({
|
||||
conversationId,
|
||||
});
|
||||
conversation.setArchived(false);
|
||||
showConversation({
|
||||
conversationId,
|
||||
})(dispatch, getState, null);
|
||||
};
|
||||
}
|
||||
|
||||
function onMarkUnread(conversationId: string): ShowToastActionType {
|
||||
|
@ -2326,12 +2333,10 @@ function createGroup(
|
|||
),
|
||||
},
|
||||
});
|
||||
dispatch(
|
||||
showConversation({
|
||||
conversationId: conversation.id,
|
||||
switchToAssociatedView: true,
|
||||
})
|
||||
);
|
||||
showConversation({
|
||||
conversationId: conversation.id,
|
||||
switchToAssociatedView: true,
|
||||
})(dispatch, getState, null);
|
||||
} catch (err) {
|
||||
log.error('Failed to create group', Errors.toLogFormat(err));
|
||||
dispatch({ type: 'CREATE_GROUP_REJECTED' });
|
||||
|
@ -3483,14 +3488,27 @@ function showConversation({
|
|||
conversationId,
|
||||
messageId,
|
||||
switchToAssociatedView,
|
||||
}: ShowConversationArgsType): SelectedConversationChangedActionType {
|
||||
return {
|
||||
type: SELECTED_CONVERSATION_CHANGED,
|
||||
payload: {
|
||||
conversationId,
|
||||
messageId,
|
||||
switchToAssociatedView,
|
||||
},
|
||||
}: ShowConversationArgsType): ThunkAction<
|
||||
void,
|
||||
RootStateType,
|
||||
unknown,
|
||||
SelectedConversationChangedActionType
|
||||
> {
|
||||
return (dispatch, getState) => {
|
||||
const { conversations } = getState();
|
||||
|
||||
if (conversationId === conversations.selectedConversationId) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: SELECTED_CONVERSATION_CHANGED,
|
||||
payload: {
|
||||
conversationId,
|
||||
messageId,
|
||||
switchToAssociatedView,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -359,7 +359,13 @@ describe('both/state/ducks/conversations', () => {
|
|||
const state = {
|
||||
...getEmptyState(),
|
||||
};
|
||||
const action = showConversation({ conversationId: 'abc123' });
|
||||
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');
|
||||
|
@ -370,10 +376,12 @@ describe('both/state/ducks/conversations', () => {
|
|||
const state = {
|
||||
...getEmptyState(),
|
||||
};
|
||||
const action = showConversation({
|
||||
const dispatch = sinon.spy();
|
||||
showConversation({
|
||||
conversationId: 'abc123',
|
||||
messageId: 'xyz987',
|
||||
});
|
||||
})(dispatch, getEmptyRootState, null);
|
||||
const action = dispatch.getCall(0).args[0];
|
||||
const nextState = reducer(state, action);
|
||||
|
||||
assert.equal(nextState.selectedConversationId, 'abc123');
|
||||
|
@ -384,10 +392,12 @@ describe('both/state/ducks/conversations', () => {
|
|||
let action: SelectedConversationChangedActionType;
|
||||
|
||||
beforeEach(() => {
|
||||
action = showConversation({
|
||||
const dispatch = sinon.spy();
|
||||
showConversation({
|
||||
conversationId: 'fake-conversation-id',
|
||||
switchToAssociatedView: true,
|
||||
});
|
||||
})(dispatch, getEmptyRootState, null);
|
||||
[action] = dispatch.getCall(0).args;
|
||||
});
|
||||
|
||||
it('shows the inbox if the conversation is not archived', () => {
|
||||
|
|
Loading…
Reference in a new issue