import http from './http'; import { getConfig } from '../utils/config'; function routes() { return getConfig().routes?.chat || {}; } export function fetchColleagues() { return http.get(routes().colleagues).then((r) => r.data); } export function fetchRooms(params = {}) { return http.get(routes().rooms, { params }).then((r) => r.data); } export function fetchRoom(roomId) { return http.get(`${routes().rooms}/${roomId}`).then((r) => r.data); } export function fetchMessages(roomId, params = {}) { return http.get(`${routes().rooms}/${roomId}/messages`, { params }).then((r) => r.data); } export function sendMessage(roomId, body) { return http.post(`${routes().rooms}/${roomId}/messages`, { body }).then((r) => r.data); } export function markRead(roomId) { return http.post(`${routes().rooms}/${roomId}/read`); } export function sendTyping(roomId) { return http.post(`${routes().rooms}/${roomId}/typing`); } export function sendHeartbeat() { return http.post(routes().heartbeat); } export function createRoom(payload) { return http.post(routes().createRoom, payload).then((r) => r.data); } export function addMember(roomId, userId) { return http.post(`${routes().rooms}/${roomId}/members`, { user_id: userId }).then((r) => r.data); } export function removeMember(roomId, userId) { return http.delete(`${routes().rooms}/${roomId}/members/${userId}`).then((r) => r.data); }