Skip to content

Commit

Permalink
feat: v3 only
Browse files Browse the repository at this point in the history
this version bump removes all v2 functionality

BREAKING CHANGE: This commit removes all v2 functionality creating a pure v3 experience.
  • Loading branch information
nplasterer committed Nov 12, 2024
1 parent c4758a8 commit 7a7c08a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 114 deletions.
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (3.0.1):
- XMTP (3.0.3):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 3.0.0)
Expand All @@ -458,7 +458,7 @@ PODS:
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 3.0.1)
- XMTP (= 3.0.3)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 00937113c4e6055980dcff9a51f8b70de83605aa
XMTPReactNative: 21011caca6d56cf3128b672fcba791b2009bb704
XMTP: ab14d9456330823f1c52b08ce5281d1e20c03f7f
XMTPReactNative: f7c9dc2eadef5c7d9590d2b7764ab805d16c7a5e
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,10 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-xmtpreactnativesdkexample/Pods-xmtpreactnativesdkexample-frameworks.sh",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/Pre-built/hermes.framework/hermes",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OpenSSL.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/hermes.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
121 changes: 14 additions & 107 deletions example/src/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import {
useXmtp,
DecodedMessage,
} from 'xmtp-react-native-sdk'
import { Group } from 'xmtp-react-native-sdk/lib/Group'

import { SupportedContentTypes } from './contentTypes/contentTypes'
import { useConversationList, useGroupsList, useMessages } from './hooks'
import { useConversationList } from './hooks'

/// Show the user's list of conversations.

Expand All @@ -30,17 +29,11 @@ export default function HomeScreen() {
isFetching,
isRefetching,
} = useConversationList()
const {
data: groups,
refetch: refetchGroups,
isFetching: isFetchingGroups,
isRefetching: isRefetchingGroups,
} = useGroupsList()
return (
<>
<View>
<Text style={{ fontSize: 24, fontWeight: 'bold', textAlign: 'center' }}>
DMs
Inbox
</Text>
<FlatList
refreshing={isFetching || isRefetching}
Expand Down Expand Up @@ -70,29 +63,15 @@ export default function HomeScreen() {
}
/>
</View>
<View>
<Text style={{ fontSize: 24, fontWeight: 'bold', textAlign: 'center' }}>
Groups
</Text>
<FlatList
refreshing={isFetchingGroups || isRefetchingGroups}
onRefresh={refetchGroups}
data={groups || []}
keyExtractor={(item) => item.id}
renderItem={({ item: group }) => (
<GroupListItem group={group} client={client} />
)}
/>
</View>
</>
)
}

function GroupListItem({
group,
function ConversationItem({
conversation,
client,
}: {
group: Group<any>
conversation: Conversation<any>
client: Client<any> | null
}) {
const navigation = useContext(NavigationContext)
Expand All @@ -103,30 +82,30 @@ function GroupListItem({
const [consentState, setConsentState] = useState<string | undefined>()

const denyGroup = async () => {
await group.updateConsent('denied')
const consent = await group.consentState()
await conversation.updateConsent('denied')
const consent = await conversation.consentState()
setConsentState(consent)
}

useEffect(() => {
group
conversation
?.sync()
.then(() => group.messages())
.then(() => conversation.messages())
.then(setMessages)
.then(() => group.consentState())
.then(() => conversation.consentState())
.then((result) => {
setConsentState(result)
})
.catch((e) => {
console.error('Error fetching group messages: ', e)
console.error('Error fetching conversation messages: ', e)
})
}, [group])
}, [conversation])

return (
<Pressable
onPress={() =>
navigation!.navigate('group', {
id: group.id,
navigation!.navigate('conversation', {
id: conversation.id,
})
}
>
Expand Down Expand Up @@ -160,75 +139,3 @@ function GroupListItem({
</Pressable>
)
}

function ConversationItem({
conversation,
client,
}: {
conversation: Conversation<any>
client: Client<any> | null
}) {
const navigation = useContext(NavigationContext)
const { data: messages } = useMessages({ topic: conversation.topic })
const lastMessage = messages?.[0]
const [getConsentState, setConsentState] = useState<string | undefined>()

useEffect(() => {
conversation
.consentState()
.then((result) => {
setConsentState(result)
})
.catch((e) => {
console.error('Error setting consent state: ', e)
})
}, [conversation])

const denyContact = async () => {
await conversation.updateConsent('denied')
conversation
.consentState()
.then(setConsentState)
.catch((e) => {
console.error('Error denying contact: ', e)
})
}

return (
<Pressable
onPress={() =>
navigation!.navigate('conversation', {
topic: conversation.topic,
})
}
>
<View
style={{
flexDirection: 'row',
padding: 8,
}}
>
<View style={{ padding: 4 }}>
<Text style={{ fontWeight: 'bold' }}>
({messages?.length} messages)
</Text>
<Button
title="Deny"
onPress={denyContact}
disabled={getConsentState === 'denied'}
/>
</View>
<View style={{ padding: 4 }}>
<Text numberOfLines={1} ellipsizeMode="tail">
{lastMessage?.fallback}
</Text>
<Text>{lastMessage?.senderAddress}:</Text>
<Text>{moment(lastMessage?.sentNs / 1000000).fromNow()}</Text>
<Text style={{ fontWeight: 'bold', color: 'red' }}>
{getConsentState}
</Text>
</View>
</View>
</Pressable>
)
}
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 3.0.1"
s.dependency "XMTP", "= 3.0.3"
end

0 comments on commit 7a7c08a

Please sign in to comment.