OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / chat / last-message / last-message.selector.js

27 lines · javascript ref:
import { createSelector as t } from "@reduxjs/toolkit"
import { EMPTY_ARRAY as e } from "../../lib/array"
import { EMPTY_OBJ as s } from "../../lib/object"
import { CHAT_STATE_KEY as a } from "../chat.constant"
import { LAST_MESSAGE_STATE_KEY as o } from "./last-message.constant"
export const getChatLastMessageByRoomId = (t) => t[a][o]
export const getChatLastMessage = (t, e) => getChatLastMessageByRoomId(t)[e] || s
export const makeGetChatLastMessageMentions = (s) =>
  t(
    (t) => getChatLastMessage(t, s).message?.chat?.mentions,
    (t) => {
      if (!t || 0 === t.length) return e
      const s = {}
      for (const { memberId: e } of t) s[e] = !0
      return Object.keys(s)
    },
  )
export const makeGetChatLastMessageMemberIds = (e) => {
  const s = makeGetChatLastMessageMentions(e)
  return t(
    (t) => getChatLastMessage(t, e).message?.memberId,
    (t) => getChatLastMessage(t, e).message?.local,
    s,
    (t, e, s) => (e || !t ? s : 0 === s.length ? [t] : s.includes(t) ? s : s.concat(t)),
  )
}