Skip to content
Open
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
32 changes: 19 additions & 13 deletions shared/chat/conversation/messages/attachment/file.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as C from '@/constants'
import * as CryptoRoutes from '@/constants/crypto'
import * as Chat from '@/stores/chat'
import * as Crypto from '@/stores/crypto'
import {isPathSaltpack, isPathSaltpackEncrypted, isPathSaltpackSigned} from '@/util/path'
import type * as T from '@/constants/types'
import {useOrdinal} from '@/chat/conversation/messages/ids-context'
import captialize from 'lodash/capitalize'
import * as Kb from '@/common-adapters'
import type {StyleOverride} from '@/common-adapters/markdown'
import {getEditStyle, ShowToastAfterSaving} from './shared'
import {useFSState} from '@/stores/fs'
import {makeUUID} from '@/util/uuid'

type OwnProps = {showPopup: () => void}

Expand Down Expand Up @@ -46,11 +46,18 @@ function FileContainer(p: OwnProps) {
const {conversationIDKey, fileType, downloadPath, isEditing, progress, messageAttachmentNativeShare} = data
const {attachmentDownload, title, transferState, transferErrMsg, fileName: _fileName} = data

const saltpackOpenFile = Crypto.useCryptoState(s => s.dispatch.onSaltpackOpenFile)
const switchTab = C.useRouterState(s => s.dispatch.switchTab)
const onSaltpackFileOpen = (path: string, operation: T.Crypto.Operations) => {
const navigateAppend = C.useRouterState(s => s.dispatch.navigateAppend)
const onSaltpackFileOpen = (path: string, name: typeof CryptoRoutes.decryptTab | typeof CryptoRoutes.verifyTab) => {
switchTab(C.Tabs.cryptoTab)
saltpackOpenFile(operation, path)
navigateAppend({
name,
params: {
entryNonce: makeUUID(),
seedInputPath: path,
seedInputType: 'file',
},
}, true)
}
const openLocalPathInSystemFileManagerDesktop = useFSState(
s => s.dispatch.defer.openLocalPathInSystemFileManagerDesktop
Expand All @@ -59,7 +66,6 @@ function FileContainer(p: OwnProps) {
downloadPath && openLocalPathInSystemFileManagerDesktop?.(downloadPath)
}

const navigateAppend = C.useRouterState(s => s.dispatch.navigateAppend)
const onDownload = () => {
if (C.isMobile) {
messageAttachmentNativeShare(ordinal, true)
Expand Down Expand Up @@ -100,12 +106,12 @@ function FileContainer(p: OwnProps) {

const progressLabel = Chat.messageAttachmentTransferStateToProgressLabel(transferState)
const iconType = isSaltpackFile ? 'icon-file-saltpack-32' : 'icon-file-32'
const operation = isPathSaltpackEncrypted(fileName)
? Crypto.Operations.Decrypt
const cryptoRoute = isPathSaltpackEncrypted(fileName)
? CryptoRoutes.decryptTab
: isPathSaltpackSigned(fileName)
? Crypto.Operations.Verify
? CryptoRoutes.verifyTab
: undefined
const operationTitle = captialize(operation)
const actionTitle = captialize(cryptoRoute?.replace('Tab', ''))

const styleOverride = Kb.Styles.isMobile
? ({paragraph: getEditStyle(isEditing)} as StyleOverride)
Expand Down Expand Up @@ -159,14 +165,14 @@ function FileContainer(p: OwnProps) {
)}
</Kb.Box2>
</Kb.Box2>
{!Kb.Styles.isMobile && isSaltpackFile && operation && (
{!Kb.Styles.isMobile && isSaltpackFile && cryptoRoute && (
<Kb.Box2 direction="vertical" fullWidth={true} style={styles.saltpackOperationContainer}>
<Kb.Button
mode="Secondary"
small={true}
label={operationTitle}
label={actionTitle}
style={styles.saltpackOperation}
onClick={() => onSaltpackFileOpen(fileName, operation)}
onClick={() => onSaltpackFileOpen(fileName, cryptoRoute)}
/>
</Kb.Box2>
)}
Expand Down
7 changes: 0 additions & 7 deletions shared/constants/crypto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,3 @@ export const Tabs = [
title: 'Verify',
},
] as const

export const Operations = {
Decrypt: 'decrypt',
Encrypt: 'encrypt',
Sign: 'sign',
Verify: 'verify',
} as const
24 changes: 19 additions & 5 deletions shared/constants/init/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ import type * as UseSettingsPasswordStateType from '@/stores/settings-password'
import type * as UseSignupStateType from '@/stores/signup'
import type * as UseTeamsStateType from '@/stores/teams'
import type * as UseTracker2StateType from '@/stores/tracker'
import type * as UseUnlockFoldersStateType from '@/stores/unlock-folders'
import type * as UnlockFoldersType from '@/stores/unlock-folders'
import type * as UseUsersStateType from '@/stores/users'
import {createTBStore, getTBStore} from '@/stores/team-building'
import {getSelectedConversation} from '@/constants/chat/common'
import * as CryptoRoutes from '@/constants/crypto'
import {emitDeepLink} from '@/router-v2/linking'
import {ignorePromise} from '../utils'
import {isMobile, serverConfigFileName} from '../platform'
Expand All @@ -50,7 +51,6 @@ import {useAutoResetState} from '@/stores/autoreset'
import {useAvatarState} from '@/common-adapters/avatar/store'
import {useChatState} from '@/stores/chat'
import {useConfigState} from '@/stores/config'
import {useCryptoState} from '@/stores/crypto'
import {useCurrentUserState} from '@/stores/current-user'
import {useDaemonState} from '@/stores/daemon'
import {useDarkModeState} from '@/stores/darkmode'
Expand Down Expand Up @@ -181,7 +181,21 @@ export const initTeamBuildingCallbacks = () => {
...(namespace === 'crypto'
? {
onFinishedTeamBuildingCrypto: users => {
useCryptoState.getState().dispatch.onTeamBuildingFinished(users)
const visible = Util.getVisibleScreen()
const visibleParams =
visible?.name === 'cryptoTeamBuilder' ? (visible.params as {teamBuilderNonce?: string} | undefined) : undefined
const teamBuilderUsers = [...users].map(({serviceId, username}) => ({serviceId, username}))
Util.clearModals()
Util.navigateAppend(
{
name: CryptoRoutes.encryptTab,
params: {
teamBuilderNonce: visibleParams?.teamBuilderNonce,
teamBuilderUsers,
},
},
true
)
},
}
: {}),
Expand Down Expand Up @@ -934,8 +948,8 @@ export const _onEngineIncoming = (action: EngineGen.Actions) => {
case 'keybase.1.rekeyUI.refresh':
case 'keybase.1.rekeyUI.delegateRekeyUI':
{
const {useUnlockFoldersState} = require('@/stores/unlock-folders') as typeof UseUnlockFoldersStateType
useUnlockFoldersState.getState().dispatch.onEngineIncomingImpl(action)
const {onUnlockFoldersEngineIncoming} = require('@/stores/unlock-folders') as typeof UnlockFoldersType
onUnlockFoldersEngineIncoming(action)
}
break
default:
Expand Down
14 changes: 9 additions & 5 deletions shared/constants/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {isSplit} from './chat/layout'
import {isMobile} from './platform'
import {shallowEqual} from './utils'
import {registerDebugClear} from '@/util/debug'
import {makeUUID} from '@/util/uuid'

type InferComponentProps<T> =
T extends React.LazyExoticComponent<React.ComponentType<infer P extends Record<string, unknown> | undefined>> ? P
Expand Down Expand Up @@ -191,7 +192,7 @@ export const navUpToScreen = (name: RouteKeys) => {
DEBUG_NAV && console.log('[Nav] navUpToScreen', {name})
const n = _getNavigator()
if (!n) return
n.dispatch(StackActions.popTo(name))
n.dispatch(StackActions.popTo(typeof name === 'string' ? name : String(name)))
}

export const navigateAppend = (path: PathParam, replace?: boolean) => {
Expand All @@ -209,8 +210,9 @@ export const navigateAppend = (path: PathParam, replace?: boolean) => {
if (typeof path === 'string') {
routeName = path
} else {
routeName = path.name
params = path.params as object
const nextPath = path as {name: string | number | symbol; params?: object}
routeName = typeof nextPath.name === 'string' ? nextPath.name : String(nextPath.name)
params = nextPath.params
}
if (!routeName) {
DEBUG_NAV && console.log('[Nav] navigateAppend no routeName bail', routeName)
Expand Down Expand Up @@ -271,9 +273,10 @@ export const navToThread = (conversationIDKey: T.Chat.ConversationIDKey) => {
// A single reset on the tab navigator atomically switches tabs and sets params.
const tabNavState = rs.routes?.[0]?.state
if (!tabNavState?.key) return
const chatTabIndex = tabNavState.routes.findIndex(r => r.name === Tabs.chatTab)
const tabRoutes = tabNavState.routes as Array<Route>
const chatTabIndex = tabRoutes.findIndex(r => r.name === Tabs.chatTab)
if (chatTabIndex < 0) return
const updatedRoutes = tabNavState.routes.map((route, i) => {
const updatedRoutes = tabRoutes.map((route, i) => {
if (i !== chatTabIndex) return route
return {...route, state: {...(route.state ?? {}), index: 0, routes: [{name: 'chatRoot', params: {conversationIDKey}}]}}
})
Expand Down Expand Up @@ -335,6 +338,7 @@ export const appendEncryptRecipientsBuilder = () => {
goButtonLabel: 'Add',
namespace: 'crypto',
recommendedHideYourself: true,
teamBuilderNonce: makeUUID(),
title: 'Recipients',
},
})
Expand Down
Loading