OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-store / store / ui-mobile / ui.reducer.js

247 lines · javascript ref:
import { createSlice as t } from "@reduxjs/toolkit"
import { MAX_AUDIO_SAMPLES as e, UI_APP_STATE as o, UI_MOBILE_STATE_KEY as a } from "./ui.constants"
import { setAppCurrentRoomId as s, getAppStatusLoading as i } from "../app/app.reducer"
import { callReset as p, callLeave as r } from "../call/call-status.action"
const I = {
  appState: o.INIT,
  appActive: !0,
  shareContent: [],
  shareRoomId: "",
  call: {
    audioCurrentOutput: "earpiece",
    audioOutputs: [],
    speakerOn: !1,
    isLoading: !1,
    nativeCallRinging: !1,
    screenVideoTrackId: null,
  },
  deviceIsOnSilentMode: !1,
  onboarding: { showWalkthroughTooltip: !1, walkthroughStep: 0 },
  appModal: { showModal: !1, queue: [] },
  appNavigator: { currentRoute: "", isMounted: !1, isInitialized: !1 },
  stats: { showStats: !1, collapseStats: !0, statsExpanded: !1, statsVisible: !1 },
  bottomSheet: { showBottomSheet: !1, sheetType: 0 },
  voiceMessage: {
    currentSoundUri: "",
    uri: "",
    audioSamples: [],
    duration: 0,
    isLocked: !1,
    isStopped: !1,
    isRecording: !1,
  },
  room: { chatBarHeight: 0, isShowEmojiKeyboard: !1, isShowPhotoPicker: !1, isShowInputExtras: !1 },
  passcode: { isAuthenticated: !0 },
}
export const uiMobileSlice = t({
  name: a,
  initialState: I,
  reducers: {
    setUIAppState: (t, e) => {
      t.appState = e.payload || o.INIT
    },
    setUIAppActive: (t, { payload: e }) => {
      t.appActive = e
    },
    setUIShowAppModal: (t, { payload: e }) => {
      t.appModal = { showModal: !0, queue: "queue" in t.appModal ? [...t.appModal.queue, e] : [e] }
    },
    setUICloseAppModal: (t) => {
      const e = "queue" in t.appModal ? t.appModal.queue : []
      e.length > 1 ? e.shift() : (t.appModal = { showModal: !1, queue: [] })
    },
    setUIBottomSheetType: (t, e) => {
      t.bottomSheet.sheetType = e.payload
    },
    setUIShowBottomSheet: (t, e) => {
      t.bottomSheet.showBottomSheet = e.payload
    },
    setUIShareContent: (t, e) => {
      t.shareContent = e.payload
    },
    setUIShareRoomId: (t, e) => {
      t.shareRoomId = e.payload
    },
    setUICallCurrentAudioOutput: (t, e) => {
      t.call.audioCurrentOutput = e.payload
    },
    setUICallAudioOutputs: (t, e) => {
      t.call.audioOutputs = e.payload
    },
    setUICallSpeaker: (t, e) => {
      t.call.speakerOn = e.payload
    },
    setUIIsCallLoading: (t, e) => {
      t.call.isLoading = e.payload
    },
    setUINativeCallRinging: (t, e) => {
      t.call.nativeCallRinging = e.payload
    },
    setUICallScreenVideoTrackId: (t, e) => {
      t.call.screenVideoTrackId = e.payload
    },
    setUIShowWalkthroughTooltip: (t) => {
      t.onboarding.showWalkthroughTooltip = !0
    },
    setUICloseWalkthroughTooltip: (t) => {
      t.onboarding.showWalkthroughTooltip = !1
    },
    setUIWalkthroughStep: (t, e) => {
      t.onboarding.walkthroughStep = e.payload
    },
    setUIDeviceSilentMode: (t, e) => {
      t.deviceIsOnSilentMode = e.payload
    },
    setUIMountNavigator: (t) => {
      t.appNavigator.isMounted = !0
    },
    setUIInitializeNavigator: (t) => {
      t.appNavigator.isInitialized = !0
    },
    setUICurrentRoute: (t, e) => {
      t.appNavigator.currentRoute = e.payload
    },
    setUIShowStats: (t, e) => {
      const { collapseStats: o } = t.stats,
        a = e.payload
      ;((t.stats.statsVisible = a && o), (t.stats.showStats = a))
    },
    setUICollapseStats: (t, e) => {
      const { showStats: o } = t.stats,
        a = e.payload
      ;((t.stats.statsVisible = o && a), (t.stats.collapseStats = a))
    },
    setUIStatsExpanded: (t, e) => {
      t.stats.statsExpanded = e.payload
    },
    setUICurrentSoundUri: (t, e) => {
      t.voiceMessage.currentSoundUri = e.payload
    },
    setUIVoiceMessageRecording: (t, e) => {
      t.voiceMessage.isRecording = e.payload
    },
    setUIVoiceMessageState: (t, e) => {
      t.voiceMessage = { ...t.voiceMessage, ...e.payload }
    },
    setUIAudioSamples: (t, o) => {
      t.voiceMessage = {
        ...t.voiceMessage,
        audioSamples: [...t.voiceMessage.audioSamples.slice(-e), o.payload],
      }
    },
    setUIChatBarHeight: (t, e) => {
      t.room.chatBarHeight = e.payload
    },
    setUIIsShowEmojiKeyboard: (t, e) => {
      t.room.isShowEmojiKeyboard = e.payload
    },
    setUIIsShowPhotoPicker: (t, e) => {
      t.room.isShowPhotoPicker = e.payload
    },
    setUIIsShowInputExtras: (t, e) => {
      t.room.isShowInputExtras = e.payload
    },
    setUIUserAuthenticationStatus: (t, { payload: e }) => {
      t.passcode.isAuthenticated = e.isAuthenticated
    },
  },
  extraReducers: (t) => {
    ;(t.addCase(s, (t, e) => {
      e.payload?.roomId || (t.room = I.room)
    }),
      t.addCase(p, (t) => {
        t.call.screenVideoTrackId = null
      }),
      t.addCase(r, (t) => {
        t.call.screenVideoTrackId = null
      }))
  },
})
export const getUIState = (t) => t[a]
export const getUIAppState = (t) => getUIState(t).appState
export const getUIAppActive = (t) => getUIState(t).appActive
export const getUIAppBackgrounded = (t) => getUIAppState(t) === o.BACKGROUND
export const getUIAppForegrounded = (t) => getUIAppState(t) === o.ACTIVE
export const getUIDeviceSilentMode = (t) => getUIState(t).deviceIsOnSilentMode
export const getUICallCurrentAudioOutput = (t) => getUIState(t).call.audioCurrentOutput
export const getUICallAudioOutputs = (t) => getUIState(t).call.audioOutputs
export const getUICallSpeaker = (t) => getUIState(t).call.speakerOn
export const getUIIsCallLoading = (t) => getUIState(t).call.isLoading
export const getUINativeCallRinging = (t) => getUIState(t).call.nativeCallRinging
export const getUIScreenVideoTrackId = (t) => getUIState(t).call.screenVideoTrackId
export const getUIShareContent = (t) => getUIState(t).shareContent || []
export const getUIShareRoomId = (t) => getUIState(t).shareRoomId
export const getUIPushNotificationPermissionsGranted = (t) =>
  getUIState(t).pushNotificationPermissionsGranted
export const getUIShowBottomSheet = (t) => getUIState(t).bottomSheet.showBottomSheet
export const getUIBottomSheetType = (t) => getUIState(t).bottomSheet.sheetType
export const getUIAppModal = (t) => getUIState(t).appModal
export const getUIAppShowModal = (t) => getUIAppModal(t).showModal
export const getUIAppModalData = (t) => {
  const e = getUIAppModal(t)
  return "queue" in e && e.queue.length > 0 ? e.queue[0] : null
}
export const getUIWalkthroughTooltip = (t) => getUIState(t).onboarding.showWalkthroughTooltip
export const getUIWalkthroughStep = (t) => getUIState(t).onboarding.walkthroughStep
export const getUIAppNavigatorMounted = (t) => getUIState(t).appNavigator.isMounted
export const getUIAppNavigatorInitialized = (t) => getUIState(t).appNavigator.isInitialized
export const getUIAppNavigatorCurrentRoute = (t) => getUIState(t).appNavigator.currentRoute
export const getUIAppNavigatorReady = (t) =>
  getUIAppNavigatorInitialized(t) && getUIAppNavigatorMounted(t)
export const getIsUIAppReady = (t) => !i(t) && getUIAppNavigatorMounted(t)
export const getUIShowStats = (t) => getUIState(t).stats.showStats
export const getUICollapseStats = (t) => getUIState(t).stats.collapseStats
export const getUIStatsExpanded = (t) => getUIState(t).stats.statsExpanded
export const getUIStatsVisible = (t) => getUIState(t).stats.statsVisible
export const getUIVmCurrentSoundUri = (t) => getUIState(t).voiceMessage.currentSoundUri
export const getUIVmUri = (t) => getUIState(t).voiceMessage.uri
export const getUIVmAudioSamples = (t) => getUIState(t).voiceMessage.audioSamples
export const getUIVmStopped = (t) => getUIState(t).voiceMessage.isStopped
export const getUIVmDuration = (t) => getUIState(t).voiceMessage.duration
export const getUIVmLocked = (t) => getUIState(t).voiceMessage.isLocked
export const getUIVmIsRecording = (t) => getUIState(t).voiceMessage.isRecording
export const getUIVmShowAudioPlayer = (t) =>
  getUIVmStopped(t) && !!getUIVmUri(t) && !!getUIVmDuration(t)
export const getUIRoomState = (t) => getUIState(t).room
export const getUIChatBarHeight = (t) => getUIRoomState(t).chatBarHeight
export const getUIIsShowEmojiKeyboard = (t) => getUIRoomState(t).isShowEmojiKeyboard
export const getUIIsShowPhotoPicker = (t) => getUIRoomState(t).isShowPhotoPicker
export const getUIIsShowInputExtras = (t) => getUIRoomState(t).isShowInputExtras
export const getUIPasscodeState = (t) => getUIState(t).passcode
export const getUIUserAuthenticationStatus = (t) => getUIPasscodeState(t).isAuthenticated
export const {
  setUIAppState: setUIAppState,
  setUIBottomSheetType: setUIBottomSheetType,
  setUIShowBottomSheet: setUIShowBottomSheet,
  setUIShareContent: setUIShareContent,
  setUIShareRoomId: setUIShareRoomId,
  setUIAppActive: setUIAppActive,
  setUIShowAppModal: setUIShowAppModal,
  setUICloseAppModal: setUICloseAppModal,
  setUICallCurrentAudioOutput: setUICallCurrentAudioOutput,
  setUICallAudioOutputs: setUICallAudioOutputs,
  setUICallSpeaker: setUICallSpeaker,
  setUIShowWalkthroughTooltip: setUIShowWalkthroughTooltip,
  setUICloseWalkthroughTooltip: setUICloseWalkthroughTooltip,
  setUIWalkthroughStep: setUIWalkthroughStep,
  setUIDeviceSilentMode: setUIDeviceSilentMode,
  setUIMountNavigator: setUIMountNavigator,
  setUIInitializeNavigator: setUIInitializeNavigator,
  setUICurrentRoute: setUICurrentRoute,
  setUIShowStats: setUIShowStats,
  setUICollapseStats: setUICollapseStats,
  setUIStatsExpanded: setUIStatsExpanded,
  setUICurrentSoundUri: setUICurrentSoundUri,
  setUIVoiceMessageRecording: setUIVoiceMessageRecording,
  setUIVoiceMessageState: setUIVoiceMessageState,
  setUIAudioSamples: setUIAudioSamples,
  setUIChatBarHeight: setUIChatBarHeight,
  setUIIsShowEmojiKeyboard: setUIIsShowEmojiKeyboard,
  setUIIsShowPhotoPicker: setUIIsShowPhotoPicker,
  setUIIsShowInputExtras: setUIIsShowInputExtras,
  setUIIsCallLoading: setUIIsCallLoading,
  setUIUserAuthenticationStatus: setUIUserAuthenticationStatus,
  setUINativeCallRinging: setUINativeCallRinging,
  setUICallScreenVideoTrackId: setUICallScreenVideoTrackId,
} = uiMobileSlice.actions