Skip to content

Commit

Permalink
add ability to list group members in android
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jun 3, 2024
1 parent 59505df commit b3a84df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import com.facebook.common.util.Hex
import expo.modules.xmtpreactnativesdk.wrappers.MemberWrapper
import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.messages.Topic
import org.xmtp.android.library.push.Service
Expand Down Expand Up @@ -805,6 +806,15 @@ class XMTPModule : Module() {
}
}

AsyncFunction("listGroupMember") Coroutine { clientAddress: String, groupId: String ->
withContext(Dispatchers.IO) {
logV("listGroupMember")
val client = clients[clientAddress] ?: throw XMTPException("No client")
val group = findGroup(clientAddress, groupId)
group?.members().map { MemberWrapper.encode(it) }
}
}

AsyncFunction("syncGroups") Coroutine { clientAddress: String ->
withContext(Dispatchers.IO) {
logV("syncGroups")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.gson.GsonBuilder
import org.xmtp.android.library.Client
import org.xmtp.android.library.Conversation
import org.xmtp.android.library.Group
import org.xmtp.android.library.codecs.Attachment
import org.xmtp.android.library.toHex
import uniffi.xmtpv3.GroupPermissions

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package expo.modules.xmtpreactnativesdk.wrappers

import com.google.gson.GsonBuilder
import org.xmtp.android.library.libxmtp.Member
import org.xmtp.android.library.libxmtp.PermissionLevel

class MemberWrapper {
companion object {
fun encodeToObj(member: Member): Map<String, Any> {
val permissionString = when (member.permissionLevel) {
PermissionLevel.MEMBER -> "member"
PermissionLevel.ADMIN -> "admin"
PermissionLevel.SUPER_ADMIN -> "super_admin"
}
return mapOf(
"inboxId" to member.inboxId,
"addresses" to member.addresses,
"permissionLevel" to permissionString
)
}

fun encode(member: Member): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(member)
return gson.toJson(obj)
}
}
}

0 comments on commit b3a84df

Please sign in to comment.