OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / ui-mobile / ui-room.saga.js

101 lines · javascript ref:
import {
  all as i,
  delay as o,
  getContext as t,
  put as e,
  race as r,
  select as n,
  take as a,
  call as l,
} from "redux-saga/effects"
import { taskErrorNotification as s } from "../error"
import {
  getRoomLastPairing as c,
  joinRoomSubmit as d,
  ROOM_DM_REPLY as m,
  setPairingRoom as p,
  setRoomPairError as y,
} from "../room"
import { setSyncDeviceErrorMsg as g, isInvitation as f } from "../identity"
import { userErrorNotification as u, userInfoNotification as R } from "../notification"
import { APP_CONTEXT_KEY as E, PLATFORM_CONTEXT_KEY as v } from "../constants"
import { isSetString as C } from "../lib/string"
import { ERROR_MESSAGES as S, TEMP_ERROR_MESSAGES as h } from "./ui.constants"
import { appRoomJoinSaga as H } from "../app"
import { getUIAppNavigatorCurrentRoute as M } from "./ui.reducer"
export function* getCoreApiErrorTitle(i) {
  const { localeManager: o } = yield t(E),
    { errorMessages: e } = o.getStrings()
  if (!i) return
  const r = i.split(":")?.[0],
    n = i
  return r && S[r] ? S[r](e) : n && h[n] ? h[n](e) : n
}
export function* uiJoinRoomHandler({ payload: { link: i } }) {
  try {
    const { navigationConstants: o, navigationHelpers: s, localeManager: c } = yield t(E),
      { config: d } = yield t(v)
    if (!C(i)) return
    if (!f(i, d.recognizedAppProtocolList)) {
      const i = c.getStrings()
      yield e(
        u({ title: i.room.roomInvitation, message: i.room.invalidInvitation, showDetails: !1 }),
      )
    }
    const [m, R, S] = yield r([a(p), a(y), a(g)]),
      h = yield n(M)
    if (R) {
      const i = yield l(getCoreApiErrorTitle, R?.payload)
      return void (
        i &&
        h === o.SCREEN_ROOM &&
        (yield e(u({ title: i, showDetails: !1 })), yield e(y("")))
      )
    }
    if (S) {
      const i = yield l(getCoreApiErrorTitle, S?.payload)
      return void (
        i &&
        h === o.SCREEN_ROOM &&
        (yield e(u({ title: i, showDetails: !1 })), yield e(g("")))
      )
    }
    m || h === o.SCREEN_HOME || s.reset(o.APP_ROOT)
  } catch (i) {
    yield s("uiJoinRoomHandler", i)
  }
}
export function* uiBatchJoinRoomHandler({ payload: o }) {
  try {
    const { navigationHelpers: e } = yield t(E)
    if (!Number(o.length)) return
    const r = yield o.map((i) => l(H, d({ link: i })))
    ;(yield i(r), e.popToTop())
  } catch (i) {
    yield s("uiBatchJoinRoomHandler", i)
  }
}
export function* uiRoomPairingNotificationSaga() {
  try {
    const { localeManager: i } = yield t(E),
      r = yield n(c)
    if (!r) return
    const a = i.getStrings(),
      l = r?.status
    ;(yield e(R({ message: a.room.pairingNotification[l] })), yield o(500))
  } catch (i) {
    yield s("uiRoomPairingNotificationSaga", i)
  }
}
export function* navigateBackSaga() {
  const { navigationHelpers: i } = yield t(E)
  i.back()
}
export function* navigateAfterDmReply({ payload: i }) {
  const { roomId: o, type: e } = i || {}
  if (e !== m.REJECT) return
  const { navigationHelpers: r, navigationConstants: a } = yield t(E),
    l = r.getCurrentRouteParams()
  ;(yield n(M)) === a.SCREEN_ROOM_DM_REQUEST && l?.dmRequest?.requestId?.roomId === o && r.back()
}