OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / chat / init / chat-init.reducer.js

34 lines · javascript ref:
import { resetModuleStateCmd as e } from "../../lib/rootAction"
import { memberDeviceOwnerChangeEvt as t } from "../../member"
import { chatInit as r, chatReset as o } from "./chat-init.action"
import { chatMessageMemberUpdateReducer as a } from "./chat-member-update.reducer"
export const getChatInitReducer = (s) => (m, i) => {
  switch (i.type) {
    case r.type: {
      const { roomId: e, startSeq: t, anchor: r, filterNames: o } = i.payload,
        { currentRoomId: a } = m
      let s = m
      return (
        a &&
          (s = { ...s, error: `unable to init chat for the room <${e}>, prev is active <${a}>` }),
        {
          ...s,
          currentRoomId: e,
          filterNames: o,
          listView: { ...m.listView, startSeq: t, anchor: r },
        }
      )
    }
    case o.type: {
      const { lastMessageByRoomId: e, draftMessageByRoomId: t } = m
      return { ...s, lastMessageByRoomId: e, draftMessageByRoomId: t }
    }
    case t.type:
      return a(m, i)
    case e.type:
      return s
    default:
      return m
  }
}