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 e237f5b85..a84f69d63 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt @@ -86,17 +86,20 @@ class ClientTest { @Test fun testPublicCanMessage() { - val fixtures = fixtures() - val aliceWallet = fixtures.aliceClient + val aliceWallet = PrivateKeyBuilder() val notOnNetwork = PrivateKeyBuilder() - val identity = PrivateKeyBuilder().getPrivateKey() - val authorized = fixtures.aliceAccount.createIdentity(identity) - val authToken = authorized.createAuthToken() - val api = fixtures.aliceClient.apiClient - api.setAuthToken(authToken) + val opts = ClientOptions(ClientOptions.Api(XMTPEnvironment.LOCAL, false)) + val aliceClient = Client().create(aliceWallet, opts) + aliceClient.ensureUserContactPublished() + + val canMessage = Client.canMessage( + aliceWallet.address, + ClientOptions(ClientOptions.Api(XMTPEnvironment.LOCAL, false)) + ) + val cannotMessage = Client.canMessage( + notOnNetwork.address, + ) - val canMessage = Client.canMessage(aliceWallet.address, apiClient = api) - val cannotMessage = Client.canMessage(notOnNetwork.address, apiClient = api) 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 7ac8d64ec..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,10 +114,17 @@ class Client() { ) ) } - fun canMessage(peerAddress: String, options: ClientOptions? = null, apiClient: ApiClient? = null): Boolean { + + fun canMessage(peerAddress: String, options: ClientOptions? = null): Boolean { val clientOptions = options ?: ClientOptions() - val api = apiClient ?: GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure) - return runBlocking { api.queryTopic(Topic.contact(peerAddress)).envelopesList.size > 0 } + val api = GRPCApiClient( + environment = clientOptions.api.env, + secure = clientOptions.api.isSecure + ) + return runBlocking { + val topics = api.queryTopic(Topic.contact(peerAddress)).envelopesList + topics.isNotEmpty() + } } }