Skip to content

Commit

Permalink
expose canMessage method
Browse files Browse the repository at this point in the history
  • Loading branch information
kele-leanes committed Nov 28, 2023
1 parent 65a3ed1 commit 8c80e3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.xmtp.android.library

import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.messages.PrivateKeyBuilder
Expand Down Expand Up @@ -82,4 +83,16 @@ class ClientTest {
assert(canMessage)
assert(!cannotMessage)
}
@Test
@Ignore("CI Issues")
fun testPublicCanMessage() {
val fixtures = fixtures()
val notOnNetwork = PrivateKeyBuilder()
val clientOptions =
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false, appVersion = "XMTPTest/v1.0.0"))
val canMessage = Client.canMessage(fixtures.bobClient.address, clientOptions)
val cannotMessage = Client.canMessage(notOnNetwork.address, clientOptions)
assert(canMessage)
assert(!cannotMessage)
}
}
5 changes: 5 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class Client() {
)
)
}
fun canMessage(peerAddress: String, options: ClientOptions? = null): Boolean {
val clientOptions = options ?: ClientOptions()
val apiClient = GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
return runBlocking { apiClient.queryTopic(Topic.contact(peerAddress)).envelopesList.size > 0 }
}
}

constructor(
Expand Down

0 comments on commit 8c80e3f

Please sign in to comment.