import { CONVERSATION_API } from '../../utils/ResourceConstants' import { createAjaxRoute, lessThanThreeErrors } from '../utils/apiHelpers' import { IFetchConversationsByIdOptions, IGetAllOpenAndPendingConvosOptions, IGetMessagesForConversationOptions } from './interfaces' export const fetchConversationsById = (options: IFetchConversationsByIdOptions) => { return createAjaxRoute({ url: `${CONVERSATION_API}/conversations/find?withReceipts=true`, method: 'POST', token: options.accessToken, body: JSON.stringify({ ids: options.listOfConversationIds }), }) .retryWhen(lessThanThreeErrors) .map((data: any) => data.response) } export const fetchInboxes = (accessToken: string) => { return createAjaxRoute({ url: `${CONVERSATION_API}/inboxes`, method: 'GET', token: accessToken, }) .retryWhen(lessThanThreeErrors) .map((data: any) => data.response) } export const getAllOpenAndPendingConvos = (options: IGetAllOpenAndPendingConvosOptions) => { return createAjaxRoute({ url: `${CONVERSATION_API}/inboxes/${options.inbox}/conversations?limit=3000&status=OPEN&status=PENDING&participantId=${options.userId}`, method: 'GET', token: options.accessToken, }) .retryWhen(lessThanThreeErrors) .map((data: any) => data.response) } export const getMessagesForConversation = (options: IGetMessagesForConversationOptions) => { return createAjaxRoute({ url: `${CONVERSATION_API}/conversations/${options.conversationId}/messages?withReceipts=true`, method: 'GET', token: options.accessToken, }) .retryWhen(lessThanThreeErrors) .map((data: any) => data.response) }