Skip to content

Commit

Permalink
feat: added removeConversation method
Browse files Browse the repository at this point in the history
  • Loading branch information
supersnager committed Feb 17, 2022
1 parent fc15d8c commit 44f58d6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/provider/ChatProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type ChatContextProps = ChatState & {
setDraft: (message: string) => void;
sendTyping: (params: SendTypingParams) => void;
addConversation: (conversation: Conversation) => void;
removeConversation: (
conversationId: ConversationId,
removeMessages: boolean | undefined
) => boolean;
getConversation: (conversationId: ConversationId) => Conversation | undefined;
updateState: () => void;
setCurrentMessage: (message: string) => void;
Expand Down Expand Up @@ -472,6 +476,22 @@ export const ChatProvider = <S extends IChatService>({
[storage, updateState]
);

/**
* Remove conversation from collection
* @param conversationId
*/
const removeConversation = useCallback(
(
conversationId: ConversationId,
removeMessages: boolean | undefined = true
) => {
const result = storage.removeConversation(conversationId, removeMessages);
updateState();
return result;
},
[storage, updateState]
);

const resetState = useCallback(() => {
storage.resetState();
updateState();
Expand Down Expand Up @@ -534,6 +554,7 @@ export const ChatProvider = <S extends IChatService>({
setDraft,
sendTyping,
addConversation,
removeConversation,
getConversation,
setCurrentMessage,
resetState,
Expand Down

0 comments on commit 44f58d6

Please sign in to comment.