Skip to content

Commit

Permalink
refactor: Change remove message and end stream message function to async
Browse files Browse the repository at this point in the history
  • Loading branch information
tjtanjin committed Sep 14, 2024
1 parent 4899665 commit bf913e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/hooks/internal/useMessagesInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const useMessagesInternal = () => {
/**
* Removes a message with the given id.
*/
const removeMessage = useCallback((messageId: string): string | null => {
const removeMessage = useCallback(async (messageId: string): Promise<string | null> => {
const message = messages.find(msg => msg.id === messageId);

// nothing to remove if no such message
Expand Down Expand Up @@ -211,7 +211,7 @@ export const useMessagesInternal = () => {
return updatedMessages;
});
return streamMessageMap.current.get(sender) || null;
},[]);
}, []);

/**
* Sets the streaming mode of the chatbot.
Expand All @@ -227,7 +227,7 @@ export const useMessagesInternal = () => {
* be made mandatory. Another key implication of not using `endStreamMessage` in v2 is that the stop stream
* message event will not be emitted, which may be problematic for logic (or plugins) that rely on this event.
*/
const endStreamMessage = (sender = "bot"): boolean => {
const endStreamMessage = useCallback(async (sender = "bot"): Promise<boolean> => {
// nothing to end if not streaming
if (!streamMessageMap.current.has(sender)) {
return true;
Expand All @@ -245,7 +245,7 @@ export const useMessagesInternal = () => {
streamMessageMap.current.delete(sender);
saveChatHistory(messages);
return true;
}
}, [messages]);

return {
endStreamMessage,
Expand Down
4 changes: 2 additions & 2 deletions src/types/Params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export type Params = {
setTextAreaValue: (value: string) => void;
injectMessage: (content: string | JSX.Element, sender?: string) => Promise<string | null>;
streamMessage: (content: string | JSX.Element, sender?: string) => Promise<string | null>;
removeMessage: (id: string) => string | null;
endStreamMessage: (sender: string) => boolean;
removeMessage: (id: string) => Promise<string | null>;
endStreamMessage: (sender: string) => Promise<boolean>;
showToast: (content: string | JSX.Element, timeout?: number) => void;
dismissToast: (id: string) => string | null;
openChat: (isOpen: boolean) => void;
Expand Down

0 comments on commit bf913e5

Please sign in to comment.