From d48013a875ca48c7e47255e2a6708ea3b0b6e91e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 11 Nov 2024 10:26:59 -0800 Subject: [PATCH] update the example app --- example/src/ConversationCreateScreen.tsx | 4 +- example/src/ConversationScreen.tsx | 2 +- example/src/GroupScreen.tsx | 2 +- example/src/HomeScreen.tsx | 8 +- example/src/LaunchScreen.tsx | 52 ++----- example/src/StreamScreen.tsx | 2 +- example/src/TestScreen.tsx | 20 +-- example/src/hooks.tsx | 45 ++---- example/src/tests/conversationTests.ts | 27 ++-- example/src/tests/dmTests.ts | 167 +++++++++++++++++++++++ example/src/types/typeTests.ts | 4 +- src/lib/Conversations.ts | 2 +- 12 files changed, 216 insertions(+), 119 deletions(-) create mode 100644 example/src/tests/dmTests.ts diff --git a/example/src/ConversationCreateScreen.tsx b/example/src/ConversationCreateScreen.tsx index 6973bb6ac..9d8e2440b 100644 --- a/example/src/ConversationCreateScreen.tsx +++ b/example/src/ConversationCreateScreen.tsx @@ -22,7 +22,7 @@ export default function ConversationCreateScreen({ } if (groupsEnabled) { const toAddresses = toAddress.split(',') - const canMessage = await client.canGroupMessage(toAddresses) + const canMessage = await client.canMessage(toAddresses) if (!canMessage) { setAlert(`${toAddress} cannot be added to a group conversation yet`) return @@ -30,7 +30,7 @@ export default function ConversationCreateScreen({ const group = await client.conversations.newGroup(toAddresses) navigation.navigate('group', { id: group.id }) } else { - const canMessage = await client.canMessage(toAddress) + const canMessage = await client.canMessage([toAddress]) if (!canMessage) { setAlert(`${toAddress} is not on the XMTP network yet`) return diff --git a/example/src/ConversationScreen.tsx b/example/src/ConversationScreen.tsx index 6cbe84d64..45304e7b9 100644 --- a/example/src/ConversationScreen.tsx +++ b/example/src/ConversationScreen.tsx @@ -959,7 +959,7 @@ function MessageItem({ {message.senderAddress.slice(-4)} - {moment(message.sent).fromNow()} + {moment(message.sentNs / 1000000).fromNow()} )} diff --git a/example/src/GroupScreen.tsx b/example/src/GroupScreen.tsx index f3ca36fb4..43d856377 100644 --- a/example/src/GroupScreen.tsx +++ b/example/src/GroupScreen.tsx @@ -959,7 +959,7 @@ function MessageItem({ {message.senderAddress.slice(-4)} - {moment(message.sent).fromNow()} + {moment(message.sentNs / 1000000).fromNow()} )} diff --git a/example/src/HomeScreen.tsx b/example/src/HomeScreen.tsx index d67cf3288..882ab48ca 100644 --- a/example/src/HomeScreen.tsx +++ b/example/src/HomeScreen.tsx @@ -103,7 +103,7 @@ function GroupListItem({ const [consentState, setConsentState] = useState() const denyGroup = async () => { - await client?.contacts.denyGroups([group.id]) + await group.updateConsent('denied') const consent = await group.consentState() setConsentState(consent) } @@ -154,7 +154,7 @@ function GroupListItem({ {lastMessage?.fallback} {lastMessage?.senderAddress}: - {moment(lastMessage?.sent).fromNow()} + {moment(lastMessage?.sentNs / 1000000).fromNow()} @@ -185,7 +185,7 @@ function ConversationItem({ }, [conversation]) const denyContact = async () => { - await client?.contacts.deny([conversation.peerAddress]) + await conversation.updateConsent('denied') conversation .consentState() .then(setConsentState) @@ -223,7 +223,7 @@ function ConversationItem({ {lastMessage?.fallback} {lastMessage?.senderAddress}: - {moment(lastMessage?.sent).fromNow()} + {moment(lastMessage?.sentNs / 1000000).fromNow()} {getConsentState} diff --git a/example/src/LaunchScreen.tsx b/example/src/LaunchScreen.tsx index 91332479d..8e9ac0f1a 100644 --- a/example/src/LaunchScreen.tsx +++ b/example/src/LaunchScreen.tsx @@ -10,7 +10,7 @@ import { useXmtp } from 'xmtp-react-native-sdk' import { NavigationParamList } from './Navigation' import { TestCategory } from './TestScreen' import { supportedCodecs } from './contentTypes/contentTypes' -import { useSavedKeys } from './hooks' +import { useSavedAddress } from './hooks' const appVersion = 'XMTP_RN_EX/0.0.1' @@ -65,11 +65,10 @@ export default function LaunchScreen( const [selectedNetwork, setSelectedNetwork] = useState< 'dev' | 'local' | 'production' >('dev') - const [enableGroups, setEnableGroups] = useState('true') const signer = useSigner() const [signerAddressDisplay, setSignerAddressDisplay] = useState() const { setClient } = useXmtp() - const savedKeys = useSavedKeys() + const savedKeys = useSavedAddress() const configureWallet = useCallback( (label: string, configuring: Promise>) => { console.log('Connecting XMTP client', label) @@ -81,8 +80,7 @@ export default function LaunchScreen( setClient(client) navigation.navigate('home') // Save the configured client keys for use in later sessions. - const keyBundle = await client.exportKeyBundle() - await savedKeys.save(keyBundle) + await savedKeys.save(client.address) }) .catch((err) => console.log('Unable to connect XMTP client', label, err) @@ -91,14 +89,6 @@ export default function LaunchScreen( [] ) - const preCreateIdentityCallback = () => { - console.log('Pre Create Identity Callback') - } - - const preEnableIdentityCallback = () => { - console.log('Pre Enable Identity Callback') - } - const preAuthenticateToInboxCallback = async () => { console.log('Pre Authenticate To Inbox Callback') } @@ -191,10 +181,6 @@ export default function LaunchScreen( selectTextStyle={styles.modalSelectText} backdropPressToClose data={groupOptions} - initValue={enableGroups} - onChange={(option) => { - setEnableGroups(option.label) - }} /> @@ -209,12 +195,7 @@ export default function LaunchScreen( color="orange" onPress={() => { ;(async () => { - console.log( - 'Using network ' + - selectedNetwork + - ' and enableV3 ' + - enableGroups - ) + console.log('Using network ' + selectedNetwork) const dbEncryptionKey = await getDbEncryptionKey( selectedNetwork, @@ -227,10 +208,7 @@ export default function LaunchScreen( env: selectedNetwork, appVersion, codecs: supportedCodecs, - preCreateIdentityCallback, - preEnableIdentityCallback, preAuthenticateToInboxCallback, - enableV3: enableGroups === 'true', dbEncryptionKey, }) ) @@ -246,12 +224,7 @@ export default function LaunchScreen( color="green" onPress={() => { ;(async () => { - console.log( - 'Using network ' + - selectedNetwork + - ' and enableV3 ' + - enableGroups - ) + console.log('Using network ' + selectedNetwork) const dbEncryptionKey = await getDbEncryptionKey( selectedNetwork, true @@ -262,10 +235,7 @@ export default function LaunchScreen( env: selectedNetwork, appVersion, codecs: supportedCodecs, - preCreateIdentityCallback, - preEnableIdentityCallback, preAuthenticateToInboxCallback, - enableV3: enableGroups === 'true', dbEncryptionKey, }) ) @@ -273,7 +243,7 @@ export default function LaunchScreen( }} /> - {!!savedKeys.keyBundle && ( + {!!savedKeys.address && ( <>