Skip to content

Commit

Permalink
Added description functions on android
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Jul 2, 2024
1 parent 0e71d60 commit 1f5c18d
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import org.xmtp.proto.keystore.api.v1.Keystore.TopicMap.TopicData
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.contents.Invitation.ConsentProofPayload
import org.xmtp.proto.message.contents.PrivateKeyOuterClass
import uniffi.xmtpv3.GroupPermissions
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration
import java.io.File
import java.util.Date
import java.util.UUID
Expand Down Expand Up @@ -411,11 +411,14 @@ class XMTPModule : Module() {

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

val client = clients[inboxId] ?: throw XMTPException("No client")

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

AsyncFunction("canGroupMessage") Coroutine { inboxId: String, peerAddresses: List<String> ->
Expand All @@ -426,13 +429,15 @@ class XMTPModule : Module() {
}
}

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 @@ -826,19 +831,20 @@ class XMTPModule : Module() {
ConversationWrapper.encode(client, conversation)
}
}
AsyncFunction("createGroup") Coroutine { inboxId: String, peerAddresses: List<String>, permission: String, groupName: String, groupImageUrlSquare: String ->
AsyncFunction("createGroup") Coroutine { inboxId: String, peerAddresses: List<String>, permission: String, groupName: String, groupImageUrlSquare: String, groupDescription: String ->
withContext(Dispatchers.IO) {
logV("createGroup")
val client = clients[inboxId] ?: throw XMTPException("No client")
val permissionLevel = when (permission) {
"admin_only" -> GroupPermissions.ADMIN_ONLY
else -> GroupPermissions.ALL_MEMBERS
"admin_only" -> GroupPermissionPreconfiguration.ADMIN_ONLY
else -> GroupPermissionPreconfiguration.ALL_MEMBERS
}
val group = client.conversations.newGroup(
peerAddresses,
permissionLevel,
groupName,
groupImageUrlSquare
groupImageUrlSquare,
groupDescription
)
GroupWrapper.encode(client, group)
}
Expand Down Expand Up @@ -959,6 +965,26 @@ class XMTPModule : Module() {
}
}

AsyncFunction("groupDescription") Coroutine { inboxId: String, id: String ->
withContext(Dispatchers.IO) {
logV("groupDescription")
val client = clients[inboxId] ?: throw XMTPException("No client")
val group = findGroup(inboxId, id)

group?.description
}
}

AsyncFunction("updateGroupDescription") Coroutine { inboxId: String, id: String, groupDescription: String ->
withContext(Dispatchers.IO) {
logV("updateGroupDescription")
val client = clients[inboxId] ?: throw XMTPException("No client")
val group = findGroup(inboxId, id)

group?.updateGroupDescription(groupDescription)
}
}

AsyncFunction("isGroupActive") Coroutine { inboxId: String, id: String ->
withContext(Dispatchers.IO) {
logV("isGroupActive")
Expand Down

0 comments on commit 1f5c18d

Please sign in to comment.