-
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.
fix: add the iOS side of group members
- Loading branch information
1 parent
b3a84df
commit db6b566
Showing
3 changed files
with
54 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// MemberWrapper.swift | ||
// XMTPReactNative | ||
// | ||
// Created by Naomi Plasterer on 6/3/24. | ||
// | ||
|
||
import Foundation | ||
import XMTP | ||
|
||
// Wrapper around XMTP.Group to allow passing these objects back into react native. | ||
struct MemberWrapper { | ||
static func encodeToObj(_ member: XMTP.Member) throws -> [String: Any] { | ||
let permissionString = switch member.permissionLevel { | ||
case .Member: | ||
"member" | ||
case .Admin: | ||
"admin" | ||
case .SuperAdmin: | ||
"super_admin" | ||
} | ||
return [ | ||
"inboxId": member.inboxId, | ||
"addresses": member.addresses, | ||
"permissionLevel": permissionString, | ||
] | ||
} | ||
|
||
static func encode(_ member: XMTP.Member) throws -> String { | ||
let obj = try encodeToObj(member) | ||
let data = try JSONSerialization.data(withJSONObject: obj) | ||
guard let result = String(data: data, encoding: .utf8) else { | ||
throw WrapperError.encodeError("could not encode member") | ||
} | ||
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