diff --git a/android/build.gradle b/android/build.gradle index 662be141..cceb99ae 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -88,6 +88,6 @@ repositories { dependencies { implementation project(':expo-modules-core') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}" - implementation "org.xmtp:android:0.1.6" + implementation "org.xmtp:android:0.1.7" implementation 'com.google.code.gson:gson:2.10.1' } diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 65905cbe..0e39441d 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -97,7 +97,7 @@ class XMTPModule : Module() { Events("sign", "authed", "conversation", "message") Function("address") { clientAddress: String -> - logV( "address"); + logV("address") val client = clients[clientAddress] client?.address ?: "No Client." } @@ -106,7 +106,7 @@ class XMTPModule : Module() { // Auth functions // AsyncFunction("auth") { address: String, environment: String -> - logV( "auth"); + logV("auth") val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address) signer = reactSigner val options = @@ -117,13 +117,13 @@ class XMTPModule : Module() { } Function("receiveSignature") { requestID: String, signature: String -> - logV( "receiveSignature"); + logV("receiveSignature") signer?.handle(id = requestID, signature = signature) } // Generate a random wallet and set the client to that AsyncFunction("createRandom") { environment: String -> - logV( "createRandom"); + logV("createRandom") val privateKey = PrivateKeyBuilder() val options = ClientOptions(api = apiEnvironments[environment] ?: apiEnvironments["dev"]!!) @@ -135,14 +135,14 @@ class XMTPModule : Module() { // // Client API AsyncFunction("canMessage") { clientAddress: String, peerAddress: String -> - logV( "canMessage"); + logV("canMessage") val client = clients[clientAddress] ?: throw XMTPException("No client") client.canMessage(peerAddress) } AsyncFunction("listConversations") { clientAddress: String -> - logV( "listConversations"); + logV("listConversations") val client = clients[clientAddress] ?: throw XMTPException("No client") val conversationList = client.conversations.list() conversationList.map { conversation -> @@ -152,28 +152,19 @@ class XMTPModule : Module() { } AsyncFunction("loadMessages") { clientAddress: String, topics: List, conversationIDs: List, limit: Int?, before: Long?, after: Long? -> - logV( "loadMessages"); - // TODO: use batchQuery instead of one-at-a-time (once Android SDK supports it). + logV("loadMessages") + val client = clients[clientAddress] ?: throw XMTPException("No client") val beforeDate = if (before != null) Date(before) else null val afterDate = if (after != null) Date(after) else null - topics.zip(conversationIDs) { topic, conversationID -> - findConversation( - clientAddress = clientAddress, - topic = topic, - conversationId = conversationID - ) - ?: throw XMTPException("no conversation found for $topic") + + client.conversations.listBatchMessages(topics, limit, beforeDate, afterDate).map { + DecodedMessageWrapper.encode(it) } - .map { - it.messages(limit = limit, before = beforeDate, after = afterDate) - .map { DecodedMessageWrapper.encode(it) } - } - .flatten() } // TODO: Support content types AsyncFunction("sendMessage") { clientAddress: String, conversationTopic: String, conversationID: String?, content: String -> - logV( "sendMessage"); + logV("sendMessage") val conversation = findConversation( clientAddress = clientAddress, @@ -188,7 +179,7 @@ class XMTPModule : Module() { } AsyncFunction("createConversation") { clientAddress: String, peerAddress: String, conversationID: String? -> - logV( "createConversation"); + logV("createConversation") val client = clients[clientAddress] ?: throw XMTPException("No client") val conversation = client.conversations.newConversation( @@ -201,12 +192,12 @@ class XMTPModule : Module() { } Function("subscribeToConversations") { clientAddress: String -> - logV( "subscribeToConversations"); + logV("subscribeToConversations") subscribeToConversations(clientAddress = clientAddress) } AsyncFunction("subscribeToMessages") { clientAddress: String, topic: String, conversationID: String? -> - logV( "subscribeToMessages"); + logV("subscribeToMessages") subscribeToMessages( clientAddress = clientAddress, topic = topic, @@ -215,7 +206,7 @@ class XMTPModule : Module() { } AsyncFunction("unsubscribeFromMessages") { clientAddress: String, topic: String, conversationID: String? -> - logV( "unsubscribeFromMessages"); + logV("unsubscribeFromMessages") unsubscribeFromMessages( clientAddress = clientAddress, topic = topic, @@ -224,13 +215,13 @@ class XMTPModule : Module() { } Function("registerPushToken") { pushServer: String, token: String -> - logV( "registerPushToken"); + logV("registerPushToken") xmtpPush = XMTPPush(appContext.reactContext!!, pushServer) xmtpPush?.register(token) } Function("subscribePushTopics") { topics: List -> - logV( "subscribePushTopics"); + logV("subscribePushTopics") if (topics.isNotEmpty()) { if (xmtpPush == null) { throw XMTPException("Push server not registered") @@ -240,7 +231,7 @@ class XMTPModule : Module() { } AsyncFunction("decodeMessage") { clientAddress: String, topic: String, encryptedMessage: String, conversationID: String? -> - logV( "decodeMessage"); + logV("decodeMessage") val encryptedMessageData = Base64.decode(encryptedMessage, Base64.NO_WRAP) val envelope = EnvelopeBuilder.buildFromString(topic, Date(), encryptedMessageData) val conversation =