Chatwoot/app/javascript/dashboard/store/modules/conversations/actions/messageReadActions.js
Sojan Jose 606fc9046a
feat: Allow users to mark a conversation as unread (#5924)
Allow users to mark conversations as unread.
Loom video: https://www.loom.com/share/ab70552d3c9c48b685da7dfa64be8bb3

fixes: #5552

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2022-11-24 10:55:45 +03:00

35 lines
970 B
JavaScript

import { throwErrorMessage } from 'dashboard/store/utils/api';
import ConversationApi from '../../../../api/inbox/conversation';
import mutationTypes from '../../../mutation-types';
export default {
markMessagesRead: async ({ commit }, data) => {
try {
const {
data: { id, agent_last_seen_at: lastSeen },
} = await ConversationApi.markMessageRead(data);
setTimeout(
() =>
commit(mutationTypes.UPDATE_MESSAGE_UNREAD_COUNT, { id, lastSeen }),
4000
);
} catch (error) {
// Handle error
}
},
markMessagesUnread: async ({ commit }, { id }) => {
try {
const {
data: { agent_last_seen_at: lastSeen, unread_count: unreadCount },
} = await ConversationApi.markMessagesUnread({ id });
commit(mutationTypes.UPDATE_MESSAGE_UNREAD_COUNT, {
id,
lastSeen,
unreadCount,
});
} catch (error) {
throwErrorMessage(error);
}
},
};