UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

27 lines 1.18 kB
import { useCallback } from "react"; import { useReplykeDispatch } from "../../../store/hooks"; import { removeMessage } from "../../../store/slices/chatSlice"; import useAxiosPrivate from "../../../config/useAxiosPrivate"; import useProject from "../../projects/useProject"; import { handleError } from "../../../utils/handleError"; function useDeleteMessage() { const dispatch = useReplykeDispatch(); const { projectId } = useProject(); const axios = useAxiosPrivate(); const deleteMsg = useCallback(async ({ conversationId, messageId }) => { if (!projectId) throw new Error("No projectId available."); try { await axios.delete(`/${projectId}/chat/conversations/${conversationId}/messages/${messageId}`); // Soft-remove locally — mirrors the server-side soft-delete behavior dispatch(removeMessage({ conversationId, messageId })); } catch (err) { handleError(err, "Failed to delete message"); throw err; } }, [projectId, axios, dispatch]); return deleteMsg; } export default useDeleteMessage; //# sourceMappingURL=useDeleteMessage.js.map