Skip to content

Commit

Permalink
fix up the test and check
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 29, 2023
1 parent d45fb24 commit 020943e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ data class GRPCApiClient(

return client.subscribe(request, headers)
}

override suspend fun subscribe2(request: Flow<SubscribeRequest>): Flow<Envelope> {
val headers = Metadata()

Expand Down
13 changes: 10 additions & 3 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down

0 comments on commit 020943e

Please sign in to comment.