diff --git a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt index c438e48c6..8a4ec2bee 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt @@ -36,7 +36,7 @@ class ClientTest { val client = Client().buildFrom(v1Copy) assertEquals( wallet.address, - client.address + client.address, ) } @@ -49,11 +49,11 @@ class ClientTest { assertEquals(client.address, clientFromV1Bundle.address) assertEquals( client.privateKeyBundleV1?.identityKey, - clientFromV1Bundle.privateKeyBundleV1?.identityKey + clientFromV1Bundle.privateKeyBundleV1?.identityKey, ) assertEquals( client.privateKeyBundleV1?.preKeysList, - clientFromV1Bundle.privateKeyBundleV1?.preKeysList + clientFromV1Bundle.privateKeyBundleV1?.preKeysList, ) } @@ -66,13 +66,14 @@ class ClientTest { assertEquals(client.address, clientFromV1Bundle.address) assertEquals( client.privateKeyBundleV1?.identityKey, - clientFromV1Bundle.privateKeyBundleV1?.identityKey + clientFromV1Bundle.privateKeyBundleV1?.identityKey, ) assertEquals( client.privateKeyBundleV1?.preKeysList, - clientFromV1Bundle.privateKeyBundleV1?.preKeysList + clientFromV1Bundle.privateKeyBundleV1?.preKeysList, ) } + @Test fun testCanMessage() { val fixtures = fixtures() @@ -82,4 +83,19 @@ class ClientTest { assert(canMessage) assert(!cannotMessage) } + + @Test + fun testPublicCanMessage() { + val aliceWallet = PrivateKeyBuilder() + val notOnNetwork = PrivateKeyBuilder() + val opts = ClientOptions(ClientOptions.Api(XMTPEnvironment.LOCAL, false)) + val aliceClient = Client().create(aliceWallet, opts) + aliceClient.ensureUserContactPublished() + + val canMessage = Client.canMessage(aliceWallet.address, opts) + val cannotMessage = Client.canMessage(notOnNetwork.address, opts) + + assert(canMessage) + assert(!cannotMessage) + } } diff --git a/library/src/main/java/org/xmtp/android/library/ApiClient.kt b/library/src/main/java/org/xmtp/android/library/ApiClient.kt index a8a19fe48..b3240e706 100644 --- a/library/src/main/java/org/xmtp/android/library/ApiClient.kt +++ b/library/src/main/java/org/xmtp/android/library/ApiClient.kt @@ -189,6 +189,7 @@ data class GRPCApiClient( return client.subscribe(request, headers) } + override suspend fun subscribe2(request: Flow): Flow { val headers = Metadata() diff --git a/library/src/main/java/org/xmtp/android/library/Client.kt b/library/src/main/java/org/xmtp/android/library/Client.kt index 9fa5f7fff..95a999da9 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -114,6 +114,18 @@ class Client() { ) ) } + + fun canMessage(peerAddress: String, options: ClientOptions? = null): Boolean { + val clientOptions = options ?: ClientOptions() + val api = GRPCApiClient( + environment = clientOptions.api.env, + secure = clientOptions.api.isSecure + ) + return runBlocking { + val topics = api.queryTopic(Topic.contact(peerAddress)).envelopesList + topics.isNotEmpty() + } + } } constructor(