-
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
cc3ffee
commit 12e06fe
Showing
4 changed files
with
55 additions
and
14 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
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
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,47 @@ | ||
// | ||
// PermissionPolicySetWrapper.swift | ||
// XMTPReactNative | ||
// | ||
// Created by Naomi Plasterer on 7/1/24. | ||
// | ||
|
||
import Foundation | ||
import XMTP | ||
|
||
class PermissionPolicySetWrapper { | ||
static func fromPermissionOption(_ permissionOption: XMTP.PermissionOption) -> String { | ||
switch permissionOption { | ||
case .allow: | ||
return "allow" | ||
case .deny: | ||
return "deny" | ||
case .admin: | ||
return "admin" | ||
case .superAdmin: | ||
return "superAdmin" | ||
case .unknown: | ||
return "unknown" | ||
} | ||
} | ||
|
||
static func encodeToObj(_ policySet: XMTP.PermissionPolicySet) -> [String: Any] { | ||
return [ | ||
"addMemberPolicy": fromPermissionOption(policySet.addMemberPolicy), | ||
"removeMemberPolicy": fromPermissionOption(policySet.removeMemberPolicy), | ||
"addAdminPolicy": fromPermissionOption(policySet.addAdminPolicy), | ||
"removeAdminPolicy": fromPermissionOption(policySet.removeAdminPolicy), | ||
"updateGroupNamePolicy": fromPermissionOption(policySet.updateGroupNamePolicy), | ||
"updateGroupDescriptionPolicy": fromPermissionOption(policySet.updateGroupDescriptionPolicy), | ||
"updateGroupImagePolicy": fromPermissionOption(policySet.updateGroupImagePolicy) | ||
] | ||
} | ||
|
||
static func encodeToJsonString(_ policySet: XMTP.PermissionPolicySet) throws -> String { | ||
let obj = encodeToObj(policySet) | ||
let data = try JSONSerialization.data(withJSONObject: obj) | ||
guard let result = String(data: data, encoding: .utf8) else { | ||
throw WrapperError.encodeError("could not encode permission policy") | ||
} | ||
return result | ||
} | ||
} |
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