diff --git a/android/build.gradle b/android/build.gradle index 6dfab186e..bb315920b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -98,7 +98,7 @@ repositories { dependencies { implementation project(':expo-modules-core') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}" - implementation "org.xmtp:android:0.10.5" + implementation "org.xmtp:android:0.10.6" 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" diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 25bafdb6d..347ce28af 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -374,10 +374,12 @@ class XMTPModule : Module() { client.canMessage(peerAddress) } - AsyncFunction("canGroupMessage") { clientAddress: String, peerAddresses: List -> - logV("canGroupMessage") - val client = clients[clientAddress] ?: throw XMTPException("No client") - client.canMessageV3(peerAddresses) + AsyncFunction("canGroupMessage") Coroutine { clientAddress: String, peerAddresses: List -> + withContext(Dispatchers.IO) { + logV("canGroupMessage") + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.canMessageV3(peerAddresses) + } } AsyncFunction("staticCanMessage") { peerAddress: String, environment: String, appVersion: String? -> diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 6d1408b5a..0cd4cd1d3 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -56,12 +56,12 @@ PODS: - hermes-engine/Pre-built (= 0.71.14) - hermes-engine/Pre-built (0.71.14) - libevent (2.1.12) - - LibXMTP (0.4.4-beta3) + - LibXMTP (0.4.4-beta5) - Logging (1.0.0) - MessagePacker (0.4.7) - - MMKV (1.3.4): - - MMKVCore (~> 1.3.4) - - MMKVCore (1.3.4) + - MMKV (1.3.5): + - MMKVCore (~> 1.3.5) + - MMKVCore (1.3.5) - OpenSSL-Universal (1.1.2200) - RCT-Folly (2021.07.22.00): - boost @@ -449,16 +449,16 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.10.5): + - XMTP (0.10.7): - Connect-Swift (= 0.12.0) - GzipSwift - - LibXMTP (= 0.4.4-beta3) + - LibXMTP (= 0.4.4-beta5) - web3.swift - XMTPReactNative (0.1.0): - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.10.5) + - XMTP (= 0.10.7) - Yoga (1.14.0) DEPENDENCIES: @@ -711,11 +711,11 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: 1422d36d715fe868b5800692f3d9b8a218a41e9d + LibXMTP: e2fb601691981900099551ff3e05621bd73dccf1 Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 - MMKV: ed58ad794b3f88c24d604a5b74f3fba17fcbaf74 - MMKVCore: a67a1cede26175c413176f404a7cedec43f96a0b + MMKV: 506311d0494023c2f7e0b62cc1f31b7370fa3cfb + MMKVCore: 9e2e5fd529b64a9fe15f1a7afb3d73b2e27b4db9 OpenSSL-Universal: 6e1ae0555546e604dbc632a2b9a24a9c46c41ef6 RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 RCTRequired: e9df143e880d0e879e7a498dc06923d728809c79 @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: ec7fa7f9a2bd3990a7142c2f454e04c5b83b834a - XMTPReactNative: 42d61df711ce3c094d9fac9e3f44671f5466e93e + XMTP: 881f30f685c5c6df83aa3bca6ca400e799256290 + XMTPReactNative: ca2bc46e645e71ce31afbbf236bc71cffc83a0f4 Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 18f423fad..414fd365f 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -728,20 +728,34 @@ test('can stream all groups and conversations', async () => { }) test('canMessage', async () => { - const bo = await Client.createRandom({ env: 'local' }) - const alix = await Client.createRandom({ env: 'local' }) + const [bo, alix, caro] = await createClients(3) const canMessage = await bo.canMessage(alix.address) if (!canMessage) { throw new Error('should be able to message v2 client') } - const [caro, chux] = await createClients(2) + const canMessageV3 = await caro.canGroupMessage([ + caro.address, + alix.address, + '0x0000000000000000000000000000000000000000', + ]) + + assert( + canMessageV3['0x0000000000000000000000000000000000000000'] === false, + `should not be able to message 0x0000000000000000000000000000000000000000` + ) + + assert( + canMessageV3[caro.address.toLowerCase()] === true, + `should be able to message ${caro.address}` + ) + + assert( + canMessageV3[alix.address.toLowerCase()] === true, + `should be able to message ${alix.address}` + ) - const canMessageV3 = await caro.canGroupMessage([chux.address]) - if (!canMessageV3) { - throw new Error('should be able to message v3 client') - } return true }) diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 317236d1c..778e169a5 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -239,7 +239,7 @@ public class XMTPModule: Module { return try await client.canMessage(peerAddress) } - AsyncFunction("canGroupMessage") { (clientAddress: String, peerAddresses: [String]) -> Bool in + AsyncFunction("canGroupMessage") { (clientAddress: String, peerAddresses: [String]) -> [String: Bool] in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index 814453097..1f03eabc0 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -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", "= 0.10.5" + s.dependency "XMTP", "= 0.10.7" end diff --git a/src/index.ts b/src/index.ts index f2af4656e..ad722b918 100644 --- a/src/index.ts +++ b/src/index.ts @@ -288,7 +288,7 @@ export async function canMessage( export async function canGroupMessage( clientAddress: string, peerAddresses: string[] -): Promise { +): Promise<{ [key: string]: boolean }> { return await XMTPModule.canGroupMessage(clientAddress, peerAddresses) } diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 714c4886c..e7571842c 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -19,11 +19,13 @@ import { DecodedMessage } from '../index' declare const Buffer -export type GetMessageContentTypeFromClient = - C extends Client ? T : never +export type GetMessageContentTypeFromClient = C extends Client + ? T + : never -export type ExtractDecodedType = - C extends XMTPModule.ContentCodec ? T : never +export type ExtractDecodedType = C extends XMTPModule.ContentCodec + ? T + : never export class Client< ContentTypes extends DefaultContentTypes = DefaultContentTypes, @@ -210,9 +212,11 @@ export class Client< * This method checks if the specified peers are using clients that support group messaging. * * @param {string[]} addresses - The addresses of the peers to check for messaging eligibility. - * @returns {Promise} A Promise resolving to true for peers where group messaging is allowed, and false otherwise. + * @returns {Promise<{ [key: string]: boolean }>} A Promise resolving to a hash of addresses and booleans if they can message on the V3 network. */ - async canGroupMessage(addresses: string[]): Promise { + async canGroupMessage( + addresses: string[] + ): Promise<{ [key: string]: boolean }> { return await XMTPModule.canGroupMessage(this.address, addresses) }