OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / chat / loader / loader.js

40 lines · javascript ref:
import { call as t } from "redux-saga/effects"
import { loadInitial as e, loadMsgsBefore as o, loadMsgsAfter as r } from "./loader-step"
import { EMPTY_ARRAY as c } from "./loader.constants"
import { CHAT_WORKER as n, MESSAGE_CATEGORY as d } from "../chat.constant"
export const createChatLoader = ({ roomId: f }) => ({
  fetch: {
    [n.INITIAL]: function* ({ query: o, count: r, ctxRef: c }) {
      const { gte: n, lte: d } = o
      return yield t(e, { roomId: f, gte: n, lte: d, count: r, ctxRef: c })
    },
    [n.TOP]: function* ({ query: e, ctxRef: r, loaded: n }) {
      const { gte: u } = n,
        a = e.gte < u ? u - e.gte : 0
      return a
        ? yield t(o, {
            roomId: f,
            topSeq: u,
            topMsgCategory: d.NO_CATEGORY,
            expectedCount: a + 1,
            ctxRef: r,
          })
        : c
    },
    [n.BOTTOM]: function* ({ query: e, ctxRef: o, count: n, loaded: u }) {
      const { lte: a } = u,
        m = e.lte > a ? e.lte - a : 0
      return m
        ? yield t(r, {
            roomId: f,
            bottomSeq: a,
            bottomMsgCategory: d.NO_CATEGORY,
            expectedCount: m + 1,
            count: n,
            ctxRef: o,
          })
        : c
    },
  },
})