OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / stats / chat-stats.selector.js

107 lines · javascript ref:
import { createSelector as t } from "@reduxjs/toolkit"
import {
  ANCHOR_STATUS as e,
  VIEW_MODE as T,
  CACHE_HIGH as o,
  getChatMessageCount as s,
  getChatMessageIds as i,
  getChatMessageSeqLoaded as S,
  getChatMessagesFetchingBottom as n,
  getChatMessagesFetchingInitial as r,
  getChatMessagesFetchingTop as A,
  getChatMessagesFetchTimeAvrg as C,
  getChatMessagesFetchTimeCount as L,
  getChatMessagesFetchTimeLatest as _,
  getChatMessageUnreadCount as p,
  getChatListViewMode as a,
  getChatMessageAnchor as m,
  getChatMessagesInView as g,
  getChatLastSeenMessageSeq as c,
  getChatListViewPaused as d,
} from "../chat"
import { getStatsTimeSendMsg as O } from "./stats.reducer"
export const CHAT_STATS_COL = {
  SL: "SL",
  IV: "IV",
  COUNT: "count",
  UC: "UC",
  LSS: "LSS",
  ML: "M.L",
  L_MODE: "L.Mode",
  P: "P",
  M_SEND: "M.Send",
  ANCHR: "Anchr",
  LOAD: "Load",
  L_AVG: "L-Avg",
}
const l = { [T.RESET]: !0, [T.RESTORE_LAST]: !0, [T.FRESH_LOADING]: !0 },
  H = { [e.ASKED]: !0, [e.LOADED]: !0 }
export const getChatStats = t(
  S,
  g,
  s,
  p,
  c,
  i,
  a,
  m,
  r,
  A,
  n,
  _,
  L,
  C,
  d,
  O,
  (t, e, T, s, i, S, n, r, A, C, L, _, p, a, m, g) => [
    {
      title: CHAT_STATS_COL.SL,
      descTop: t.top,
      isWarningTop: t.top >= e.top && 0 !== t.top,
      descBtm: t.bottom,
      isWarningBtm: t.bottom < e.bottom || (t.bottom === e.bottom && T - 1 > t.bottom),
    },
    {
      title: CHAT_STATS_COL.IV,
      descTop: e.top,
      isWarningTop: -1 === e.top,
      descBtm: e.bottom,
      isWarningBtm: -1 === e.bottom,
    },
    { title: CHAT_STATS_COL.COUNT, descTop: T },
    { title: CHAT_STATS_COL.UC, descTop: s },
    { title: CHAT_STATS_COL.LSS, descTop: i },
    { title: CHAT_STATS_COL.ML, descTop: S.length, isWarningTop: S.length > o },
    { title: CHAT_STATS_COL.L_MODE, descTop: n, isWarningTop: !!l[n] },
    { title: CHAT_STATS_COL.P, descTop: m ? "paused" : "-" },
    {
      title: CHAT_STATS_COL.ANCHR,
      descTop: r?.status ?? "-",
      isWarningTop: !!H[r?.status],
      descBtm: `${r?.seq ?? "-"}`,
      isWarningBtm: r && !Number.isInteger(r?.seq),
    },
    {
      title: CHAT_STATS_COL.LOAD,
      descTop: `${A ? "i" : ""} ${C ? "t" : ""} ${L ? "b" : ""}`,
      isWarningTop: !1,
      descBtm: `${_ ?? "-"}`,
      isWarningBtm: Number.isInteger(_) && _ > 200,
    },
    {
      title: CHAT_STATS_COL.L_AVG,
      descTop: p,
      isWarningTop: !1,
      descBtm: a,
      isWarningBtm: Number.isInteger(a) && a > 200,
    },
    {
      title: CHAT_STATS_COL.M_SEND,
      descTop: g.latest,
      isWarningTop: Number.isInteger(g.latest) && g.latest > 500,
      descBtm: g.average,
      isWarningBtm: Number.isInteger(g.average) && g.average > 500,
    },
  ],
)