Skip to content

Commit

Permalink
Fix merge conflicts with main
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Apr 1, 2024
1 parent 13b4d3a commit 5c865e6
Show file tree
Hide file tree
Showing 9 changed files with 597 additions and 25 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
implementation "org.xmtp:android:0.8.4"
implementation "org.xmtp:android:0.9.0"
// xmtp-android local testing setup below (comment org.xmtp:android above)
// implementation files('<PATH TO XMTP-ANDROID>/xmtp-android/library/build/outputs/aar/library-debug.aar')
// implementation 'com.google.crypto.tink:tink-android:1.7.0'
Expand Down
40 changes: 21 additions & 19 deletions android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.core.net.toUri
import com.google.gson.JsonParser
import com.google.protobuf.kotlin.toByteString
import expo.modules.kotlin.exception.Exceptions
import expo.modules.kotlin.functions.Coroutine
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.xmtpreactnativesdk.wrappers.ConsentWrapper
Expand All @@ -28,6 +29,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import org.json.JSONObject
import org.xmtp.android.library.Client
import org.xmtp.android.library.ClientOptions
Expand Down Expand Up @@ -330,7 +332,7 @@ class XMTPModule : Module() {
}

// Export the conversation's serialized topic data.
AsyncFunction("exportConversationTopicData") { clientAddress: String, topic: String ->
AsyncFunction("exportConversationTopicData") Coroutine { clientAddress: String, topic: String ->
logV("exportConversationTopicData")
val conversation = findConversation(clientAddress, topic)
?: throw XMTPException("no conversation found for $topic")
Expand Down Expand Up @@ -437,7 +439,7 @@ class XMTPModule : Module() {
).toJson()
}

AsyncFunction("sendEncodedContent") { clientAddress: String, topic: String, encodedContentData: List<Int> ->
AsyncFunction("sendEncodedContent") Coroutine { clientAddress: String, topic: String, encodedContentData: List<Int> ->
val conversation =
findConversation(
clientAddress = clientAddress,
Expand All @@ -458,7 +460,7 @@ class XMTPModule : Module() {
conversation.send(encodedContent = encodedContent)
}

AsyncFunction("listConversations") { clientAddress: String ->
AsyncFunction("listConversations") Coroutine { clientAddress: String ->
logV("listConversations")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val conversationList = client.conversations.list()
Expand Down Expand Up @@ -490,7 +492,7 @@ class XMTPModule : Module() {
}
}

AsyncFunction("loadMessages") { clientAddress: String, topic: String, limit: Int?, before: Long?, after: Long?, direction: String? ->
AsyncFunction("loadMessages") Coroutine { clientAddress: String, topic: String, limit: Int?, before: Long?, after: Long?, direction: String? ->
logV("loadMessages")
val conversation =
findConversation(
Expand Down Expand Up @@ -527,7 +529,7 @@ class XMTPModule : Module() {
)?.map { DecodedMessageWrapper.encode(it) }
}

AsyncFunction("loadBatchMessages") { clientAddress: String, topics: List<String> ->
AsyncFunction("loadBatchMessages") Coroutine { clientAddress: String, topics: List<String> ->
logV("loadBatchMessages")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val topicsList = mutableListOf<Pair<String, Pagination>>()
Expand Down Expand Up @@ -572,7 +574,7 @@ class XMTPModule : Module() {
.map { DecodedMessageWrapper.encode(it) }
}

AsyncFunction("sendMessage") { clientAddress: String, conversationTopic: String, contentJson: String ->
AsyncFunction("sendMessage") Coroutine { clientAddress: String, conversationTopic: String, contentJson: String ->
logV("sendMessage")
val conversation =
findConversation(
Expand Down Expand Up @@ -602,7 +604,7 @@ class XMTPModule : Module() {
)
}

AsyncFunction("prepareMessage") { clientAddress: String, conversationTopic: String, contentJson: String ->
AsyncFunction("prepareMessage") Coroutine { clientAddress: String, conversationTopic: String, contentJson: String ->
logV("prepareMessage")
val conversation =
findConversation(
Expand All @@ -625,7 +627,7 @@ class XMTPModule : Module() {
).toJson()
}

AsyncFunction("prepareEncodedMessage") { clientAddress: String, conversationTopic: String, encodedContentData: List<Int> ->
AsyncFunction("prepareEncodedMessage") Coroutine { clientAddress: String, conversationTopic: String, encodedContentData: List<Int> ->
logV("prepareEncodedMessage")
val conversation =
findConversation(
Expand Down Expand Up @@ -658,7 +660,7 @@ class XMTPModule : Module() {
).toJson()
}

AsyncFunction("sendPreparedMessage") { clientAddress: String, preparedLocalMessageJson: String ->
AsyncFunction("sendPreparedMessage") Coroutine { clientAddress: String, preparedLocalMessageJson: String ->
logV("sendPreparedMessage")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val local = PreparedLocalMessage.fromJson(preparedLocalMessageJson)
Expand All @@ -676,7 +678,7 @@ class XMTPModule : Module() {
prepared.messageId
}

AsyncFunction("createConversation") { clientAddress: String, peerAddress: String, contextJson: String ->
AsyncFunction("createConversation") Coroutine { clientAddress: String, peerAddress: String, contextJson: String ->
logV("createConversation: $contextJson")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val context = JsonParser.parseString(contextJson).asJsonObject
Expand Down Expand Up @@ -791,7 +793,7 @@ class XMTPModule : Module() {
subscribeToAllGroupMessages(clientAddress = clientAddress)
}

AsyncFunction("subscribeToMessages") { clientAddress: String, topic: String ->
AsyncFunction("subscribeToMessages") Coroutine { clientAddress: String, topic: String ->
logV("subscribeToMessages")
subscribeToMessages(
clientAddress = clientAddress,
Expand Down Expand Up @@ -827,7 +829,7 @@ class XMTPModule : Module() {
subscriptions[getGroupMessagesKey(clientAddress)]?.cancel()
}

AsyncFunction("unsubscribeFromMessages") { clientAddress: String, topic: String ->
AsyncFunction("unsubscribeFromMessages") Coroutine { clientAddress: String, topic: String ->
logV("unsubscribeFromMessages")
unsubscribeFromMessages(
clientAddress = clientAddress,
Expand Down Expand Up @@ -859,7 +861,7 @@ class XMTPModule : Module() {
}
}

AsyncFunction("decodeMessage") { clientAddress: String, topic: String, encryptedMessage: String ->
AsyncFunction("decodeMessage") Coroutine { clientAddress: String, topic: String, encryptedMessage: String ->
logV("decodeMessage")
val encryptedMessageData = Base64.decode(encryptedMessage, NO_WRAP)
val envelope = EnvelopeBuilder.buildFromString(topic, Date(), encryptedMessageData)
Expand All @@ -885,13 +887,13 @@ class XMTPModule : Module() {
client.contacts.isDenied(address)
}

AsyncFunction("denyContacts") { clientAddress: String, addresses: List<String> ->
AsyncFunction("denyContacts") Coroutine { clientAddress: String, addresses: List<String> ->
logV("denyContacts")
val client = clients[clientAddress] ?: throw XMTPException("No client")
client.contacts.deny(addresses)
}

AsyncFunction("allowContacts") { clientAddress: String, addresses: List<String> ->
AsyncFunction("allowContacts") Coroutine { clientAddress: String, addresses: List<String> ->
val client = clients[clientAddress] ?: throw XMTPException("No client")
client.contacts.allow(addresses)
}
Expand All @@ -902,7 +904,7 @@ class XMTPModule : Module() {
consentList.entries.map { ConsentWrapper.encode(it.value) }
}

AsyncFunction("conversationConsentState") { clientAddress: String, conversationTopic: String ->
AsyncFunction("conversationConsentState") Coroutine { clientAddress: String, conversationTopic: String ->
val conversation = findConversation(clientAddress, conversationTopic)
?: throw XMTPException("no conversation found for $conversationTopic")
consentStateToString(conversation.consentState())
Expand Down Expand Up @@ -954,7 +956,7 @@ class XMTPModule : Module() {
// Helpers
//

private fun findConversation(
private suspend fun findConversation(
clientAddress: String,
topic: String,
): Conversation? {
Expand Down Expand Up @@ -1118,7 +1120,7 @@ class XMTPModule : Module() {
}
}

private fun subscribeToMessages(clientAddress: String, topic: String) {
private suspend fun subscribeToMessages(clientAddress: String, topic: String) {
val conversation =
findConversation(
clientAddress = clientAddress,
Expand Down Expand Up @@ -1188,7 +1190,7 @@ class XMTPModule : Module() {
return "groups:$clientAddress"
}

private fun unsubscribeFromMessages(
private suspend fun unsubscribeFromMessages(
clientAddress: String,
topic: String,
) {
Expand Down
6 changes: 6 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import GroupScreen from './src/GroupScreen'
import HomeScreen from './src/HomeScreen'
import LaunchScreen from './src/LaunchScreen'
import { Navigator } from './src/Navigation'
import StreamScreen from './src/StreamScreen'
import TestScreen from './src/TestScreen'

const queryClient = new QueryClient()
Expand Down Expand Up @@ -100,6 +101,11 @@ export default function App() {
component={ConversationCreateScreen}
options={{ title: 'New Conversation' }}
/>
<Navigator.Screen
name="streamTest"
component={StreamScreen}
options={{ title: 'Stream Tests' }}
/>
</Navigator.Navigator>
</NavigationContainer>
</XmtpProvider>
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
8 changes: 8 additions & 0 deletions example/src/LaunchScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ export default function LaunchScreen(
<Text style={styles.label}>External Wallet:</Text>
<ConnectWallet theme="dark" />
</View>
<View key="stream-tests" style={{ margin: 16, marginTop: 16 }}>
<Button
color="green"
title="Create Stream Tests"
onPress={() => navigation.navigate('streamTest')}
accessibilityLabel="Unit-tests"
/>
</View>
{signer && (
<>
<View key="connected-dev" style={{ margin: 16 }}>
Expand Down
1 change: 1 addition & 0 deletions example/src/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type NavigationParamList = {
group: { id: string }
conversation: { topic: string }
conversationCreate: undefined
streamTest: undefined
}

export const Navigator = createNativeStackNavigator<NavigationParamList>()
Loading

0 comments on commit 5c865e6

Please sign in to comment.