Skip to content

Commit

Permalink
Merge pull request #12 from xmtp/np/group-admins-release
Browse files Browse the repository at this point in the history
Group Admin LibXMTP Bump
  • Loading branch information
nplasterer authored Feb 21, 2024
2 parents de859c8 + 7c57fcf commit f6571b6
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 6 deletions.
4 changes: 2 additions & 2 deletions LibXMTP.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'LibXMTP'
s.version = '0.4.2-beta1'
s.version = '0.4.2-beta3'
s.summary = 'XMTP shared Rust code that powers cross-platform SDKs'

s.homepage = 'https://github.com/xmtp/libxmtp-swift'
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.platform = :ios, '13.0', :macos, '11.0'
s.swift_version = '5.3'

s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-f2eb822/LibXMTPSwiftFFI.zip", :type => :zip }
s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-e460692/LibXMTPSwiftFFI.zip", :type => :zip }
s.vendored_frameworks = 'LibXMTPRust.xcframework'
s.source_files = 'Sources/LibXMTP/**/*'
end
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let package = Package(
),
.binaryTarget(
name: "LibXMTPSwiftFFI",
url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-f2eb822/LibXMTPSwiftFFI.zip",
checksum: "12d472e239a1eb1619ab3e209abfd5d34555dde9633eb6dc466eb9f060ea4139"
url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-e460692/LibXMTPSwiftFFI.zip",
checksum: "2aae9511e2e2e49a52dcdd2d60cb58cbdb4caf75d9f0be877b85c24176ca7323"
),
.testTarget(name: "LibXMTPTests", dependencies: ["LibXMTP"]),
]
Expand Down
139 changes: 137 additions & 2 deletions Sources/LibXMTP/xmtpv3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ public protocol FfiConversationsProtocol {
func createGroup(accountAddresses: [String], permissions: GroupPermissions?) async throws -> FfiGroup
func list(opts: FfiListConversationsOptions) async throws -> [FfiGroup]
func stream(callback: FfiConversationCallback) async throws -> FfiStreamCloser
func streamAllMessages(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser
func sync() async throws
}

Expand Down Expand Up @@ -494,6 +495,22 @@ public class FfiConversations: FfiConversationsProtocol {
)
}

public func streamAllMessages(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser {
return try await uniffiRustCallAsync(
rustFutureFunc: {
uniffi_xmtpv3_fn_method_fficonversations_stream_all_messages(
self.pointer,
FfiConverterCallbackInterfaceFfiMessageCallback.lower(messageCallback)
)
},
pollFunc: ffi_xmtpv3_rust_future_poll_pointer,
completeFunc: ffi_xmtpv3_rust_future_complete_pointer,
freeFunc: ffi_xmtpv3_rust_future_free_pointer,
liftFunc: FfiConverterTypeFfiStreamCloser.lift,
errorHandler: FfiConverterTypeGenericError.lift
)
}

public func sync() async throws {
return try await uniffiRustCallAsync(
rustFutureFunc: {
Expand Down Expand Up @@ -552,6 +569,7 @@ public protocol FfiGroupProtocol {
func addMembers(accountAddresses: [String]) async throws
func createdAtNs() -> Int64
func findMessages(opts: FfiListMessagesOptions) throws -> [FfiMessage]
func groupMetadata() throws -> FfiGroupMetadata
func id() -> Data
func isActive() throws -> Bool
func listMembers() throws -> [FfiGroupMember]
Expand Down Expand Up @@ -609,6 +627,14 @@ public class FfiGroup: FfiGroupProtocol {
)
}

public func groupMetadata() throws -> FfiGroupMetadata {
return try FfiConverterTypeFfiGroupMetadata.lift(
rustCallWithError(FfiConverterTypeGenericError.lift) {
uniffi_xmtpv3_fn_method_ffigroup_group_metadata(self.pointer, $0)
}
)
}

public func id() -> Data {
return try! FfiConverterData.lift(
try!
Expand Down Expand Up @@ -736,6 +762,91 @@ public func FfiConverterTypeFfiGroup_lower(_ value: FfiGroup) -> UnsafeMutableRa
return FfiConverterTypeFfiGroup.lower(value)
}

public protocol FfiGroupMetadataProtocol {
func conversationType() -> String
func creatorAccountAddress() -> String
func policyType() throws -> GroupPermissions
}

public class FfiGroupMetadata: FfiGroupMetadataProtocol {
fileprivate let pointer: UnsafeMutableRawPointer

// TODO: We'd like this to be `private` but for Swifty reasons,
// we can't implement `FfiConverter` without making this `required` and we can't
// make it `required` without making it `public`.
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
self.pointer = pointer
}

deinit {
try! rustCall { uniffi_xmtpv3_fn_free_ffigroupmetadata(pointer, $0) }
}

public func conversationType() -> String {
return try! FfiConverterString.lift(
try!
rustCall {
uniffi_xmtpv3_fn_method_ffigroupmetadata_conversation_type(self.pointer, $0)
}
)
}

public func creatorAccountAddress() -> String {
return try! FfiConverterString.lift(
try!
rustCall {
uniffi_xmtpv3_fn_method_ffigroupmetadata_creator_account_address(self.pointer, $0)
}
)
}

public func policyType() throws -> GroupPermissions {
return try FfiConverterTypeGroupPermissions.lift(
rustCallWithError(FfiConverterTypeGenericError.lift) {
uniffi_xmtpv3_fn_method_ffigroupmetadata_policy_type(self.pointer, $0)
}
)
}
}

public struct FfiConverterTypeFfiGroupMetadata: FfiConverter {
typealias FfiType = UnsafeMutableRawPointer
typealias SwiftType = FfiGroupMetadata

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiGroupMetadata {
let v: UInt64 = try readInt(&buf)
// The Rust code won't compile if a pointer won't fit in a UInt64.
// We have to go via `UInt` because that's the thing that's the size of a pointer.
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
if ptr == nil {
throw UniffiInternalError.unexpectedNullPointer
}
return try lift(ptr!)
}

public static func write(_ value: FfiGroupMetadata, into buf: inout [UInt8]) {
// This fiddling is because `Int` is the thing that's the same size as a pointer.
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
}

public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupMetadata {
return FfiGroupMetadata(unsafeFromRawPointer: pointer)
}

public static func lower(_ value: FfiGroupMetadata) -> UnsafeMutableRawPointer {
return value.pointer
}
}

public func FfiConverterTypeFfiGroupMetadata_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupMetadata {
return try FfiConverterTypeFfiGroupMetadata.lift(pointer)
}

public func FfiConverterTypeFfiGroupMetadata_lower(_ value: FfiGroupMetadata) -> UnsafeMutableRawPointer {
return FfiConverterTypeFfiGroupMetadata.lower(value)
}

public protocol FfiStreamCloserProtocol {
func end()
func isClosed() -> Bool
Expand Down Expand Up @@ -1939,6 +2050,9 @@ public enum GenericError {
// Simple error enums only carry a message
case Signature(message: String)

// Simple error enums only carry a message
case GroupMetadata(message: String)

// Simple error enums only carry a message
case Generic(message: String)

Expand Down Expand Up @@ -1977,7 +2091,11 @@ public struct FfiConverterTypeGenericError: FfiConverterRustBuffer {
message: FfiConverterString.read(from: &buf)
)

case 7: return try .Generic(
case 7: return try .GroupMetadata(
message: FfiConverterString.read(from: &buf)
)

case 8: return try .Generic(
message: FfiConverterString.read(from: &buf)
)

Expand All @@ -1999,8 +2117,10 @@ public struct FfiConverterTypeGenericError: FfiConverterRustBuffer {
writeInt(&buf, Int32(5))
case .Signature(_ /* message is ignored*/ ):
writeInt(&buf, Int32(6))
case .Generic(_ /* message is ignored*/ ):
case .GroupMetadata(_ /* message is ignored*/ ):
writeInt(&buf, Int32(7))
case .Generic(_ /* message is ignored*/ ):
writeInt(&buf, Int32(8))
}
}
}
Expand Down Expand Up @@ -3267,6 +3387,9 @@ private var initializationResult: InitializationResult {
if uniffi_xmtpv3_checksum_method_fficonversations_stream() != 60583 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_fficonversations_stream_all_messages() != 65211 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_fficonversations_sync() != 62598 {
return InitializationResult.apiChecksumMismatch
}
Expand All @@ -3279,6 +3402,9 @@ private var initializationResult: InitializationResult {
if uniffi_xmtpv3_checksum_method_ffigroup_find_messages() != 61973 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_group_metadata() != 3690 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_id() != 35243 {
return InitializationResult.apiChecksumMismatch
}
Expand All @@ -3300,6 +3426,15 @@ private var initializationResult: InitializationResult {
if uniffi_xmtpv3_checksum_method_ffigroup_sync() != 9422 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroupmetadata_conversation_type() != 37015 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroupmetadata_creator_account_address() != 1906 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroupmetadata_policy_type() != 22845 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffistreamcloser_end() != 47211 {
return InitializationResult.apiChecksumMismatch
}
Expand Down

0 comments on commit f6571b6

Please sign in to comment.