Skip to content

Commit

Permalink
fix up the coroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jul 1, 2024
1 parent f246dc2 commit 9ea3f6d
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,24 @@ class XMTPModule : Module() {

//
// Client API
AsyncFunction("canMessage") { clientAddress: String, peerAddress: String ->
logV("canMessage")
val client = clients[clientAddress] ?: throw XMTPException("No client")
AsyncFunction("canMessage") Coroutine { clientAddress: String, peerAddress: String ->
withContext(Dispatchers.IO) {
logV("canMessage")
val client = clients[clientAddress] ?: throw XMTPException("No client")

client.canMessage(peerAddress)
client.canMessage(peerAddress)
}
}

AsyncFunction("staticCanMessage") { peerAddress: String, environment: String, appVersion: String? ->
try {
logV("staticCanMessage")
val options = ClientOptions(api = apiEnvironments(environment, appVersion))
Client.canMessage(peerAddress = peerAddress, options = options)
} catch (e: Exception) {
throw XMTPException("Failed to create client: ${e.message}")
AsyncFunction("staticCanMessage") Coroutine { peerAddress: String, environment: String, appVersion: String? ->
withContext(Dispatchers.IO) {
try {
logV("staticCanMessage")
val options = ClientOptions(api = apiEnvironments(environment, appVersion))
Client.canMessage(peerAddress = peerAddress, options = options)
} catch (e: Exception) {
throw XMTPException("Failed to create client: ${e.message}")
}
}
}

Expand Down Expand Up @@ -583,14 +587,15 @@ class XMTPModule : Module() {

var consentProof: ConsentProofPayload? = null
if (consentProofPayload.isNotEmpty()) {
val consentProofDataBytes = consentProofPayload.foldIndexed(ByteArray(consentProofPayload.size)) { i, a, v ->
a.apply {
set(
i,
v.toByte()
)
val consentProofDataBytes =
consentProofPayload.foldIndexed(ByteArray(consentProofPayload.size)) { i, a, v ->
a.apply {
set(
i,
v.toByte()
)
}
}
}
consentProof = ConsentProofPayload.parseFrom(consentProofDataBytes)
}

Expand Down

0 comments on commit 9ea3f6d

Please sign in to comment.