add a reset conversation action type and call it on message destroyed

pull/1381/head
Audric Ackermann 4 years ago
parent bb87eb0f52
commit 535b1d59ef
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -2276,8 +2276,9 @@
}); });
this.messageCollection.reset([]); this.messageCollection.reset([]);
// no need to do the trigger 'messageDeleted' here window.Whisper.events.trigger('conversationReset', {
conversationKey: this.id,
});
// destroy message keeps the active timestamp set so the // destroy message keeps the active timestamp set so the
// conversation still appears on the conversation list but is empty // conversation still appears on the conversation list but is empty
this.set({ this.set({

@ -211,6 +211,7 @@ export class SessionInboxView extends React.Component<Props, State> {
messageAdded, messageAdded,
messageChanged, messageChanged,
messageDeleted, messageDeleted,
conversationReset,
} = bindActionCreators(conversationActions, this.store.dispatch); } = bindActionCreators(conversationActions, this.store.dispatch);
window.actionsCreators = conversationActions; window.actionsCreators = conversationActions;
const { userChanged } = bindActionCreators( const { userChanged } = bindActionCreators(
@ -236,6 +237,7 @@ export class SessionInboxView extends React.Component<Props, State> {
window.Whisper.events.on('messageAdded', messageAdded); window.Whisper.events.on('messageAdded', messageAdded);
window.Whisper.events.on('messageDeleted', messageDeleted); window.Whisper.events.on('messageDeleted', messageDeleted);
window.Whisper.events.on('userChanged', userChanged); window.Whisper.events.on('userChanged', userChanged);
window.Whisper.events.on('conversationReset', conversationReset);
this.setState({ isInitialLoadComplete: true }); this.setState({ isInitialLoadComplete: true });
} }

@ -211,6 +211,12 @@ export type MessageDeletedActionType = {
messageId: string; messageId: string;
}; };
}; };
export type ConversationResetActionType = {
type: 'CONVERSATION_RESET';
payload: {
conversationKey: string;
};
};
export type SelectedConversationChangedActionType = { export type SelectedConversationChangedActionType = {
type: 'SELECTED_CONVERSATION_CHANGED'; type: 'SELECTED_CONVERSATION_CHANGED';
payload: { payload: {
@ -231,6 +237,7 @@ export type ConversationActionType =
| ConversationAddedActionType | ConversationAddedActionType
| ConversationChangedActionType | ConversationChangedActionType
| ConversationRemovedActionType | ConversationRemovedActionType
| ConversationResetActionType
| RemoveAllConversationsActionType | RemoveAllConversationsActionType
| MessageExpiredActionType | MessageExpiredActionType
| MessageAddedActionType | MessageAddedActionType
@ -250,6 +257,7 @@ export const actions = {
messageExpired, messageExpired,
messageAdded, messageAdded,
messageDeleted, messageDeleted,
conversationReset,
messageChanged, messageChanged,
fetchMessagesForConversation, fetchMessagesForConversation,
openConversationExternal, openConversationExternal,
@ -349,6 +357,19 @@ function messageDeleted({
}; };
} }
function conversationReset({
conversationKey,
}: {
conversationKey: string;
}): ConversationResetActionType {
return {
type: 'CONVERSATION_RESET',
payload: {
conversationKey,
},
};
}
function openConversationExternal( function openConversationExternal(
id: string, id: string,
messageId?: string messageId?: string
@ -553,5 +574,17 @@ export function reducer(
return state; return state;
} }
if (action.type === 'CONVERSATION_RESET') {
const { conversationKey } = action.payload;
if (conversationKey === state.selectedConversation) {
// just empty the list of messages
return {
...state,
messages: [],
};
}
return state;
}
return state; return state;
} }

Loading…
Cancel
Save