-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f5c18d
commit 04d4b80
Showing
2 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/PermissionPolicySet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package expo.modules.xmtpreactnativesdk.wrappers | ||
|
||
import com.google.gson.GsonBuilder | ||
import expo.modules.kotlin.types.Enumerable | ||
import org.xmtp.android.library.Client | ||
import org.xmtp.android.library.Group | ||
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionOption | ||
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionPolicySet | ||
|
||
enum class ExpoPermissionOption(val value: String) : Enumerable { | ||
Allow("Allow"), | ||
Deny("Deny"), | ||
Admin("Admin"), | ||
SuperAdmin("SuperAdmin"), | ||
Unknown("Unknown"); | ||
companion object { | ||
fun fromPermissionOption(permissionOption: PermissionOption): ExpoPermissionOption { | ||
return when (permissionOption) { | ||
PermissionOption.Allow -> Allow | ||
PermissionOption.Deny -> Deny | ||
PermissionOption.Admin -> Admin | ||
PermissionOption.SuperAdmin -> SuperAdmin | ||
PermissionOption.Unknown -> Unknown | ||
} | ||
} | ||
} | ||
} | ||
|
||
class PermissionPolicySetWrapper { | ||
|
||
companion object { | ||
fun encodeToObj(policySet: PermissionPolicySet): Map<String, Any> { | ||
|
||
return mapOf( | ||
"addMemberPolicy" to ExpoPermissionOption.fromPermissionOption(policySet.addMemberPolicy), | ||
"removeMemberPolicy" to ExpoPermissionOption.fromPermissionOption(policySet.removeMemberPolicy), | ||
"addAdminPolicy" to ExpoPermissionOption.fromPermissionOption(policySet.addAdminPolicy), | ||
"removeAdminPolicy" to ExpoPermissionOption.fromPermissionOption(policySet.removeAdminPolicy), | ||
"updateGroupNamePolicy" to ExpoPermissionOption.fromPermissionOption(policySet.updateGroupNamePolicy), | ||
"updateGroupDescriptionPolicy" to ExpoPermissionOption.fromPermissionOption(policySet.updateGroupDescriptionPolicy), | ||
"updateGroupImagePolicy" to ExpoPermissionOption.fromPermissionOption(policySet.updateGroupImagePolicy), | ||
) | ||
} | ||
|
||
fun encode(client: Client, group: Group): String { | ||
val gson = GsonBuilder().create() | ||
val obj = GroupWrapper.encodeToObj(client, group) | ||
return gson.toJson(obj) | ||
} | ||
} | ||
} |