Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions shared/app/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as C from '@/constants'
import {useConfigState} from '@/constants/config'
import * as Kb from '@/common-adapters'
import * as React from 'react'
import {useDeepLinksState} from '@/constants/deeplinks'
import {handleAppLink} from '@/constants/deeplinks'
import Main from './main.native'
import {KeyboardProvider} from 'react-native-keyboard-controller'
import Animated, {ReducedMotionConfig, ReduceMotion} from 'react-native-reanimated'
Expand All @@ -18,9 +18,9 @@ import ServiceDecoration from '@/common-adapters/markdown/service-decoration'
import {useUnmountAll} from '@/util/debug-react'
import {darkModeSupported, guiConfig} from 'react-native-kb'
import {install} from 'react-native-kb'
import {useEngineState} from '@/constants/engine'
import * as DarkMode from '@/constants/darkmode'
import {initPlatformListener} from '@/constants/platform-specific'
import {onEngineConnected, onEngineDisconnected} from '@/constants/platform-specific/shared'
import {initPlatformListener} from '@/constants/init'

enableFreeze(true)
setServiceDecoration(ServiceDecoration)
Expand Down Expand Up @@ -107,7 +107,6 @@ const StoreHelper = (p: {children: React.ReactNode}): React.ReactNode => {
const {children} = p
useDarkHookup()
useKeyboardHookup()
const handleAppLink = useDeepLinksState(s => s.dispatch.handleAppLink)

React.useEffect(() => {
const linkingSub = Linking.addEventListener('url', ({url}: {url: string}) => {
Expand All @@ -116,7 +115,7 @@ const StoreHelper = (p: {children: React.ReactNode}): React.ReactNode => {
return () => {
linkingSub.remove()
}
}, [handleAppLink])
}, [])

return children
}
Expand All @@ -136,9 +135,9 @@ const useInit = () => {
const {batch} = C.useWaitingState.getState().dispatch
const eng = makeEngine(batch, c => {
if (c) {
useEngineState.getState().dispatch.onEngineConnected()
onEngineConnected()
} else {
useEngineState.getState().dispatch.onEngineDisconnected()
onEngineDisconnected()
}
})
initPlatformListener()
Expand Down
3 changes: 3 additions & 0 deletions shared/chat/conversation/input-area/location-popup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type * as React from 'react'
declare const LocationPopup: () => React.ReactNode
export default LocationPopup
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const LocationPopup = () => null
export default LocationPopup
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,52 @@ import * as C from '@/constants'
import * as Chat from '@/constants/chat2'
import * as React from 'react'
import {useConfigState} from '@/constants/config'
import logger from '@/logger'
import * as Kb from '@/common-adapters'
import * as T from '@/constants/types'
import LocationMap from '@/chat/location-map'
import {useCurrentUserState} from '@/constants/current-user'
import {requestLocationPermission} from '@/constants/platform-specific'
import * as ExpoLocation from 'expo-location'

const useWatchPosition = (conversationIDKey: T.Chat.ConversationIDKey) => {
const updateLastCoord = Chat.useChatState(s => s.dispatch.updateLastCoord)
const setCommandStatusInfo = Chat.useChatContext(s => s.dispatch.setCommandStatusInfo)
React.useEffect(() => {
let unsub = () => {}
logger.info('[location] perms check due to map')
const f = async () => {
try {
await requestLocationPermission(T.RPCChat.UIWatchPositionPerm.base)
const sub = await ExpoLocation.watchPositionAsync(
{accuracy: ExpoLocation.LocationAccuracy.Highest},
(location: ExpoLocation.LocationObject) => {
const coord = {
accuracy: Math.floor(location.coords.accuracy ?? 0),
lat: location.coords.latitude,
lon: location.coords.longitude,
}
updateLastCoord(coord)
}
)
unsub = () => sub.remove()
} catch (_error) {
const error = _error as {message?: string}
logger.info('failed to get location: ' + error.message)
setCommandStatusInfo({
actions: [T.RPCChat.UICommandStatusActionTyp.appsettings],
displayText: `Failed to access location. ${error.message}`,
displayType: T.RPCChat.UICommandStatusDisplayTyp.error,
})
}
}

C.ignorePromise(f())
return () => {
unsub()
}
}, [conversationIDKey, updateLastCoord, setCommandStatusInfo])
}

const LocationPopup = () => {
const conversationIDKey = Chat.useChatContext(s => s.id)
Expand All @@ -27,17 +69,7 @@ const LocationPopup = () => {
sendMessage(duration ? `/location live ${duration}` : '/location')
}

React.useEffect(() => {
let unwatch: undefined | (() => void)
C.PlatformSpecific.watchPositionForMap(conversationIDKey)
.then(unsub => {
unwatch = unsub
})
.catch(() => {})
return () => {
unwatch?.()
}
}, [conversationIDKey])
useWatchPosition(conversationIDKey)

const width = Math.ceil(Kb.Styles.dimensionWidth)
const height = Math.ceil(Kb.Styles.dimensionHeight - 320)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as React from 'react'
import AudioRecorder from '@/chat/audio/audio-recorder.native'
import FilePickerPopup from '../filepicker-popup'
import {onHWKeyPressed, removeOnHWKeyPressed} from 'react-native-kb'
import MoreMenuPopup from './moremenu-popup'
import MoreMenuPopup from './moremenu-popup.native'
import SetExplodingMessagePicker from './set-explode-popup'
import Typing from './typing'
import type * as ImagePicker from 'expo-image-picker'
Expand Down
5 changes: 2 additions & 3 deletions shared/common-adapters/markdown/service-decoration.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as T from '@/constants/types'
import * as React from 'react'
import * as C from '@/constants'
import {useDeepLinksState} from '@/constants/deeplinks'
import {handleAppLink} from '@/constants/deeplinks'
import * as Styles from '@/styles'
import Channel from './channel'
import KbfsPath from '@/fs/common/kbfs-path'
Expand Down Expand Up @@ -29,10 +29,9 @@ type KeybaseLinkProps = {
}

const KeybaseLink = (props: KeybaseLinkProps) => {
const handleAppLink = useDeepLinksState(s => s.dispatch.handleAppLink)
const onClick = React.useCallback(() => {
handleAppLink(props.link)
}, [handleAppLink, props.link])
}, [props.link])

return (
<Text
Expand Down
3 changes: 2 additions & 1 deletion shared/constants/chat2/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as T from '../types'
import {isMobile, isTablet} from '../platform'
import * as Router2 from '../router2'
import {storeRegistry} from '../store-registry'
import {useConfigState} from '../config'

export const explodingModeGregorKeyPrefix = 'exploding:'

Expand Down Expand Up @@ -30,7 +31,7 @@ export const isUserActivelyLookingAtThisThread = (conversationIDKey: T.Chat.Conv
(maybeVisibleScreen === undefined ? undefined : maybeVisibleScreen.name) === threadRouteName
}

const {appFocused} = storeRegistry.getState('config')
const {appFocused} = useConfigState.getState()
const {active: userActive} = storeRegistry.getState('active')

return (
Expand Down
13 changes: 7 additions & 6 deletions shared/constants/chat2/convostate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {enumKeys, ignorePromise, shallowEqual} from '../utils'
import * as Strings from '@/constants/strings'

import {storeRegistry} from '../store-registry'
import {useConfigState} from '../config'
import {useCurrentUserState} from '../current-user'

const {darwinCopyToChatTempUploadFile} = KB2.functions
Expand Down Expand Up @@ -494,13 +495,13 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
}

const onClick = () => {
storeRegistry.getState('config').dispatch.showMain()
useConfigState.getState().dispatch.showMain()
storeRegistry.getState('chat').dispatch.navigateToInbox()
get().dispatch.navigateToThread('desktopNotification')
}
const onClose = () => {}
logger.info('invoking NotifyPopup for chat notification')
const sound = storeRegistry.getState('config').notifySound
const sound = useConfigState.getState().notifySound

const cleanBody = body.replaceAll(/!>(.*?)<!/g, '•••')

Expand Down Expand Up @@ -1239,7 +1240,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
blockConversation: reportUser => {
const f = async () => {
storeRegistry.getState('chat').dispatch.navigateToInbox()
storeRegistry.getState('config').dispatch.dynamic.persistRoute?.()
useConfigState.getState().dispatch.dynamic.persistRoute?.()
await T.RPCChat.localSetConversationStatusLocalRpcPromise({
conversationID: get().getConvID(),
identifyBehavior: T.RPCGen.TLFIdentifyBehavior.chatGui,
Expand Down Expand Up @@ -1754,7 +1755,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
},
markTeamAsRead: teamID => {
const f = async () => {
if (!storeRegistry.getState('config').loggedIn) {
if (!useConfigState.getState().loggedIn) {
logger.info('bail on not logged in')
return
}
Expand All @@ -1765,7 +1766,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
},
markThreadAsRead: force => {
const f = async () => {
if (!storeRegistry.getState('config').loggedIn) {
if (!useConfigState.getState().loggedIn) {
logger.info('mark read bail on not logged in')
return
}
Expand Down Expand Up @@ -2703,7 +2704,7 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
}
const conversationIDKey = get().id
const f = async () => {
if (!storeRegistry.getState('config').loggedIn) {
if (!useConfigState.getState().loggedIn) {
logger.info('mark unread bail on not logged in')
return
}
Expand Down
31 changes: 17 additions & 14 deletions shared/constants/chat2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import isEqual from 'lodash/isEqual'
import {bodyToJSON} from '../rpc-utils'
import {navigateAppend, navUpToScreen, switchTab} from '../router2/util'
import {storeRegistry} from '../store-registry'
import {useConfigState} from '../config'
import {useCurrentUserState} from '../current-user'
import {useWaitingState} from '../waiting'
import * as S from '../strings'
Expand Down Expand Up @@ -527,7 +528,7 @@ export const useChatState = Z.createZustand<State>((set, get) => {
inboxRefresh: reason => {
const f = async () => {
const {username} = useCurrentUserState.getState()
const {loggedIn} = storeRegistry.getState('config')
const {loggedIn} = useConfigState.getState()
if (!loggedIn || !username) {
return
}
Expand Down Expand Up @@ -1566,12 +1567,13 @@ export const useChatState = Z.createZustand<State>((set, get) => {
const first = resultMetas[0]
if (!first) {
if (p.reason === 'appLink') {
storeRegistry
.getState('deeplinks')
.dispatch.setLinkError(
"We couldn't find this team chat channel. Please check that you're a member of the team and the channel exists."
)
navigateAppend('keybaseLinkError')
navigateAppend({
props: {
error:
"We couldn't find this team chat channel. Please check that you're a member of the team and the channel exists.",
},
selected: 'keybaseLinkError',
})
return
} else {
return
Expand All @@ -1595,12 +1597,13 @@ export const useChatState = Z.createZustand<State>((set, get) => {
error.code === T.RPCGen.StatusCode.scteamnotfound &&
reason === 'appLink'
) {
storeRegistry
.getState('deeplinks')
.dispatch.setLinkError(
"We couldn't find this team. Please check that you're a member of the team and the channel exists."
)
navigateAppend('keybaseLinkError')
navigateAppend({
props: {
error:
"We couldn't find this team. Please check that you're a member of the team and the channel exists.",
},
selected: 'keybaseLinkError',
})
return
} else {
throw error
Expand Down Expand Up @@ -1757,7 +1760,7 @@ export const useChatState = Z.createZustand<State>((set, get) => {
unboxRows: (ids, force) => {
// We want to unbox rows that have scroll into view
const f = async () => {
if (!storeRegistry.getState('config').loggedIn) {
if (!useConfigState.getState().loggedIn) {
return
}

Expand Down
11 changes: 1 addition & 10 deletions shared/constants/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {defaultUseNativeFrame, isMobile} from '../platform'
import {type CommonResponseHandler} from '@/engine/types'
import {invalidPasswordErrorString} from './util'
import {navigateAppend} from '../router2/util'
import {storeRegistry} from '../store-registry'
import {useWhatsNewState} from '../whats-new'

type Store = T.Immutable<{
forceSmallNav: boolean
Expand Down Expand Up @@ -151,8 +149,6 @@ export interface State extends Store {
openAppSettings?: () => void
openAppStore?: () => void
onEngineConnectedDesktop?: () => void
onEngineIncomingDesktop?: (action: EngineGen.Actions) => void
onEngineIncomingNative?: (action: EngineGen.Actions) => void
persistRoute?: (path?: ReadonlyArray<unknown>) => void
setNavigatorExistsNative?: () => void
showMainNative?: () => void
Expand Down Expand Up @@ -265,9 +261,6 @@ export const useConfigState = Z.createZustand<State>((set, get) => {
set(s => {
s.allowAnimatedEmojis = allowAnimatedEmojis
})

const lastSeenItem = goodState.find(i => i.item.category === 'whatsNewLastSeenVersion')
useWhatsNewState.getState().dispatch.updateLastSeen(lastSeenItem)
}

const updateRuntimeStats = (stats?: T.RPCGen.RuntimeStats) => {
Expand Down Expand Up @@ -305,8 +298,6 @@ export const useConfigState = Z.createZustand<State>((set, get) => {
},
dumpLogsNative: undefined,
onEngineConnectedDesktop: undefined,
onEngineIncomingDesktop: undefined,
onEngineIncomingNative: undefined,
onFilePickerError: undefined,
openAppSettings: undefined,
openAppStore: undefined,
Expand Down Expand Up @@ -420,7 +411,7 @@ export const useConfigState = Z.createZustand<State>((set, get) => {
'keybase.1.provisionUi.DisplayAndPromptSecret': cancelOnCallback,
'keybase.1.provisionUi.PromptNewDeviceName': (_, response) => {
cancelOnCallback(undefined, response)
storeRegistry.getState('provision').dispatch.dynamic.setUsername?.(username)
navigateAppend({props: {username}, selected: 'username'})
},
'keybase.1.provisionUi.chooseDevice': cancelOnCallback,
'keybase.1.provisionUi.chooseGPGMethod': cancelOnCallback,
Expand Down
Loading