UNPKG

@replyke/core

Version:

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

37 lines 1.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = require("react"); const hooks_1 = require("../../store/hooks"); const chatSlice_1 = require("../../store/slices/chatSlice"); const useAxiosPrivate_1 = __importDefault(require("../../config/useAxiosPrivate")); const useProject_1 = __importDefault(require("../projects/useProject")); const handleError_1 = require("../../utils/handleError"); /** * Internal hook — called by ConversationProvider, not intended for direct use. * Advances the server-side lastReadAt to the given message's createdAt and * resets the local unread count to 0 immediately (optimistic clear). */ function useMarkConversationAsRead({ conversationId, }) { const dispatch = (0, hooks_1.useReplykeDispatch)(); const { projectId } = (0, useProject_1.default)(); const axios = (0, useAxiosPrivate_1.default)(); const mark = (0, react_1.useCallback)(async ({ messageId }) => { if (!projectId || !conversationId || !messageId) return; // Clear unread count locally for immediate UI update dispatch((0, chatSlice_1.clearUnread)(conversationId)); try { await axios.post(`/${projectId}/chat/conversations/${conversationId}/read`, { messageId }); } catch (err) { // Non-critical — don't re-throw; the local clear still stands (0, handleError_1.handleError)(err, "Failed to mark conversation as read"); } }, [projectId, conversationId, axios, dispatch]); return mark; } exports.default = useMarkConversationAsRead; //# sourceMappingURL=useMarkConversationAsRead.js.map