OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / stats / flow / start-roomList.js

67 lines · javascript ref:
import {
  setContext as o,
  select as t,
  all as e,
  call as r,
  take as m,
  race as i,
} from "redux-saga/effects"
import {
  setItemsInView as a,
  setAllRooms as n,
  setRoomInfo as d,
  getRoomState as l,
  getRoomListInViewIds as s,
  getRoomItemById as p,
} from "../../room"
import { last as y } from "../../lib/array"
import {
  TIME_CONTEXT_KEY as c,
  createTimeContext as f,
  parallel as u,
  sequence as h,
  takeStep as g,
  step as T,
} from "./flow.model"
import { updateChatLastMessage as b } from "../../chat"
import { isBlockedMembersDataEvt as I } from "../../identity/member"
const w = (o) => a.match(o) && o.payload.bottom - o.payload.top > 0,
  x = (o) => (t) => b.match(t) && t.payload.roomId === o,
  R = (o) => (t) => d.match(t) && t.payload.roomId === o && Object.keys(t.payload).length > 1
export function* statsRoomListItemSaga({ roomId: o }) {
  const [m, i, a] = yield e([r(g, x(o)), r(g, R(o)), r(g, I)]),
    { title: n } = yield t(p(o))
  return u([m, i, a], { title: n, name: "room list item" })
}
export function* statsRenderRoomListSaga({ currentTime: p } = {}) {
  const b = "render room list"
  yield o({ [c]: f(p) })
  const I = yield g(n),
    x = I.action.payload.rooms.length
  if (((I.info = `rooms count =${x}`), 0 === x)) return h(b, [I])
  const D = yield g(w)
  D.info = "rendered rooms =" + (D.action.payload.bottom - D.action.payload.top)
  const L = [D]
  let S = []
  function* j() {
    const o = yield t(s),
      { roomById: n } = yield t(l),
      [p, c] = yield i([
        e(
          o.map((o) =>
            n[o]?.title
              ? r(() => T(d, { startTime: D.doneTime, doneTime: Date.now() }))
              : r(g, R(o)),
          ),
        ),
        m(a),
      ])
    if ((p?.length && (S = p), c)) {
      const o = T(c, { startTime: y(L).doneTime, doneTime: Date.now() })
      ;((o.info = "rendered rooms =" + (c.payload.bottom - c.payload.top)), L.push(o))
    }
  }
  for (; S.length < 1; ) yield r(j)
  return h(b, [I, ...L, u(S, { name: "render room items" })])
}