Skip to content

Commit

Permalink
feat: make chat feature optional (#1297)
Browse files Browse the repository at this point in the history
Signed-off-by: fc-santos <[email protected]>
  • Loading branch information
fc-santos authored Oct 24, 2024
1 parent c9e07ca commit 99ce75c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useChatMessagesByConnection } from '../../hooks/chat-messages'
import { ContactStackParams, Screens, Stacks } from '../../types/navigators'
import { formatTime, getConnectionName } from '../../utils/helpers'
import { testIdWithKey } from '../../utils/testable'
import { TOKENS, useServices } from '../../container-api'

interface Props {
contact: ConnectionRecord
Expand All @@ -24,6 +25,7 @@ const ContactListItem: React.FC<Props> = ({ contact, navigation }) => {
const message = messages[0]
const hasOnlyInitialMessage = messages.length < 2
const [store] = useStore()
const [{ enableChat }] = useServices([TOKENS.CONFIG])

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -71,19 +73,17 @@ const ContactListItem: React.FC<Props> = ({ contact, navigation }) => {
})

const navigateToContact = useCallback(() => {
navigation
.getParent()
?.navigate(Stacks.ContactStack, { screen: Screens.Chat, params: { connectionId: contact.id } })
}, [navigation, contact])
navigation.getParent()?.navigate(Stacks.ContactStack, {
screen: enableChat ? Screens.Chat : Screens.ContactDetails,
params: { connectionId: contact.id },
})
}, [navigation, contact, enableChat])

const contactLabel = useMemo(
() => getConnectionName(contact, store.preferences.alternateContactNames),
[contact, store.preferences.alternateContactNames]
)
const contactLabelAbbr = useMemo(
() => contactLabel?.charAt(0).toUpperCase(),
[contactLabel]
)
const contactLabelAbbr = useMemo(() => contactLabel?.charAt(0).toUpperCase(), [contactLabel])

return (
<TouchableOpacity
Expand Down
7 changes: 5 additions & 2 deletions packages/legacy/core/App/container-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ import NotificationListItem from './components/listItems/NotificationListItem'
import NoNewUpdates from './components/misc/NoNewUpdates'
import PINCreateHeader from './components/misc/PINCreateHeader'
import { PersistentStorage } from './services/storage'
import { Config } from './types/config'
import { Locales } from './localization'

export const defaultConfig = {
export const defaultConfig: Config = {
PINSecurity: { rules: PINRules, displayHelper: false },
settings: [],
enableChat: true,
enableTours: false,
supportedLanguages: ['en', 'fr', 'pt-BR'],
supportedLanguages: [Locales.en, Locales.fr, Locales.ptBr],
showPreface: false,
disableOnboardingSkip: false,
whereToUseWalletUrl: 'https://example.com',
Expand Down
59 changes: 42 additions & 17 deletions packages/legacy/core/App/screens/Connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { AttestationEventTypes } from '../types/attestation'
import { BifoldError } from '../types/error'
import { EventTypes } from '../constants'
import { testIdWithKey } from '../utils/testable'
import Toast from 'react-native-toast-message'
import { ToastType } from '../components/toast/BaseToast'

type ConnectionProps = StackScreenProps<DeliveryStackParams, Screens.Connection>

Expand All @@ -46,8 +48,12 @@ const GoalCodes = {

const Connection: React.FC<ConnectionProps> = ({ navigation, route }) => {
const { oobRecordId, openIDUri, proofId, credentialId } = route.params
const [logger, { useNotifications }, { connectionTimerDelay, autoRedirectConnectionToHome }, attestationMonitor] =
useServices([TOKENS.UTIL_LOGGER, TOKENS.NOTIFICATIONS, TOKENS.CONFIG, TOKENS.UTIL_ATTESTATION_MONITOR])
const [
logger,
{ useNotifications },
{ connectionTimerDelay, autoRedirectConnectionToHome, enableChat },
attestationMonitor,
] = useServices([TOKENS.UTIL_LOGGER, TOKENS.NOTIFICATIONS, TOKENS.CONFIG, TOKENS.UTIL_ATTESTATION_MONITOR])
const connTimerDelay = connectionTimerDelay ?? 10000 // in ms
const notifications = useNotifications({ openIDUri: openIDUri })
const oobRecord = useOutOfBandById(oobRecordId ?? '')
Expand All @@ -68,6 +74,27 @@ const Connection: React.FC<ConnectionProps> = ({ navigation, route }) => {
},
})

const handleNavigation = useCallback(
(connectionId: string) => {
dispatch({ inProgress: false })
if (enableChat) {
navigation.getParent()?.dispatch(
CommonActions.reset({
index: 1,
routes: [{ name: Stacks.TabStack }, { name: Screens.Chat, params: { connectionId } }],
})
)
} else {
navigation.getParent()?.navigate(TabStacks.HomeStack, { screen: Screens.Home })
Toast.show({
type: ToastType.Success,
text1: t('Connection.ConnectionCompleted'),
})
}
},
[dispatch, navigation, enableChat, t]
)

const onDismissModalTouched = useCallback(() => {
dispatch({ inProgress: false })
navigation.getParent()?.navigate(TabStacks.HomeStack, { screen: Screens.Home })
Expand Down Expand Up @@ -133,13 +160,7 @@ const Connection: React.FC<ConnectionProps> = ({ navigation, route }) => {
if (connection && !(Object.values(GoalCodes) as [string]).includes(oobRecord?.outOfBandInvitation.goalCode ?? '')) {
logger?.info('Connection: Handling connection without goal code, navigate to Chat')

dispatch({ inProgress: false })
navigation.getParent()?.dispatch(
CommonActions.reset({
index: 1,
routes: [{ name: Stacks.TabStack }, { name: Screens.Chat, params: { connectionId: connection.id } }],
})
)
handleNavigation(connection.id)

return
}
Expand Down Expand Up @@ -188,14 +209,18 @@ const Connection: React.FC<ConnectionProps> = ({ navigation, route }) => {

logger?.info(`Connection: Unable to handle ${goalCode} goal code`)

dispatch({ inProgress: false })
navigation.getParent()?.dispatch(
CommonActions.reset({
index: 1,
routes: [{ name: Stacks.TabStack }, { name: Screens.Chat, params: { connectionId: connection.id } }],
})
)
}, [oobRecord, state.inProgress, connection, logger, dispatch, navigation, t, state.notificationRecord])
handleNavigation(connection.id)
}, [
oobRecord,
state.inProgress,
connection,
logger,
dispatch,
navigation,
t,
state.notificationRecord,
handleNavigation,
])

// This hook will monitor notification for openID type credentials
// where there is not connection or oobID present
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/core/App/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Config {
supportedLanguages: Locales[]
connectionTimerDelay?: number
autoRedirectConnectionToHome?: boolean
enableChat?: boolean
enableTours?: boolean
enableImplicitInvitations?: boolean
enableReuseConnections?: boolean
Expand Down

0 comments on commit 99ce75c

Please sign in to comment.