import { call as e } from "redux-saga/effects"
import { getCoreBackend as t } from "../backend"
let o = null
export const setApiPromiseEnhancer = (e) => {
o = e
}
export async function apiCallPromise(e, ...t) {
let n
return ((n = o ? await o(e, t) : await e(...t)), n)
}
let n = null
export const setApiEnhancer = (e) => {
n = e
}
export function* apiCall(t, ...o) {
let r
return ((r = n ? yield n(t, ...o) : yield e(t, ...o)), r)
}
export function* getRecentRoomsApi(e) {
const o = t()
return yield apiCall(o.getRecentRooms, e)
}
export function* getRoomInfoApi(e) {
const o = t()
return yield apiCall(o.getRoomInfo, e)
}
export function* searchRoomsApi() {
const e = t()
return yield apiCall(e.searchRooms)
}
export function* getVersionApi() {
const e = t()
return (yield apiCall(e.getVersion)).abi.max
}
export function getChatMessagesApiPromise(e, { reverse: o, gte: n, lte: r }) {
const i = { reverse: "boolean" != typeof o || o, lte: r, gte: n }
return apiCallPromise(t().getChatMessages, e, i)
}
export const ERROR_POSIX = { ENOSPC: "ENOSPC", EIO: "EIO" }