Skip to content

Commit

Permalink
simplify kotlin native module update
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Jul 2, 2024
1 parent 04d4b80 commit 0bb8a1f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GroupWrapper {

companion object {
fun encodeToObj(client: Client, group: Group): Map<String, Any> {
val permissionPolicySet = PermissionPolicySetWrapper.encodeToObj(group.permissionPolicySet())
val permissionPolicySet = PermissionPolicySetWrapper.encodeToJsonString(group.permissionPolicySet())
return mapOf(
"clientAddress" to client.address,
"id" to group.id.toHex(),
Expand All @@ -31,4 +31,4 @@ class GroupWrapper {
return gson.toJson(obj)
}
}
}
}

This file was deleted.

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

import com.google.gson.GsonBuilder
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionOption
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionPolicySet

class PermissionPolicySetWrapper {

companion object {
fun fromPermissionOption(permissionOption: PermissionOption): String {
return when (permissionOption) {
PermissionOption.Allow -> "allow"
PermissionOption.Deny -> "deny"
PermissionOption.Admin -> "admin"
PermissionOption.SuperAdmin -> "superAdmin"
PermissionOption.Unknown -> "unknown"
}
}
fun encodeToObj(policySet: PermissionPolicySet): Map<String, Any> {
return mapOf(
"addMemberPolicy" to fromPermissionOption(policySet.addMemberPolicy),
"removeMemberPolicy" to fromPermissionOption(policySet.removeMemberPolicy),
"addAdminPolicy" to fromPermissionOption(policySet.addAdminPolicy),
"removeAdminPolicy" to fromPermissionOption(policySet.removeAdminPolicy),
"updateGroupNamePolicy" to fromPermissionOption(policySet.updateGroupNamePolicy),
"updateGroupDescriptionPolicy" to fromPermissionOption(policySet.updateGroupDescriptionPolicy),
"updateGroupImagePolicy" to fromPermissionOption(policySet.updateGroupImagePolicy),
)
}

fun encodeToJsonString(policySet: PermissionPolicySet): String {
val gson = GsonBuilder().create()
val obj = encodeToObj(policySet)
return gson.toJson(obj)
}
}
}

0 comments on commit 0bb8a1f

Please sign in to comment.