From 6fd4804679c08bfd6f5dce28f20eb4d388f8168a Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 8 Jul 2024 11:38:33 -0600 Subject: [PATCH 1/2] dump the code --- Sources/LibXMTP/libxmtp-version.txt | 4 +- Sources/LibXMTP/xmtpv3.swift | 131 ++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 2 deletions(-) diff --git a/Sources/LibXMTP/libxmtp-version.txt b/Sources/LibXMTP/libxmtp-version.txt index cd7d5fb..d0a93e3 100644 --- a/Sources/LibXMTP/libxmtp-version.txt +++ b/Sources/LibXMTP/libxmtp-version.txt @@ -1,3 +1,3 @@ -Version: 5c78fbad +Version: d4d8134a Branch: main -Date: 2024-07-03 01:23:38 +0000 +Date: 2024-07-08 15:44:32 +0000 diff --git a/Sources/LibXMTP/xmtpv3.swift b/Sources/LibXMTP/xmtpv3.swift index 561784b..dc52ae0 100644 --- a/Sources/LibXMTP/xmtpv3.swift +++ b/Sources/LibXMTP/xmtpv3.swift @@ -751,6 +751,11 @@ public protocol FfiGroupProtocol: AnyObject { func send(contentBytes: Data) async throws -> Data + /** + * send a message without immediately publishing to the delivery service. + */ + func sendOptimistic(contentBytes: Data) throws -> FfiUnpublishedMessage + func stream(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser func superAdminList() throws -> [String] @@ -1071,6 +1076,16 @@ open class FfiGroup: ) } + /** + * send a message without immediately publishing to the delivery service. + */ + open func sendOptimistic(contentBytes: Data) throws -> FfiUnpublishedMessage { + return try FfiConverterTypeFfiUnpublishedMessage.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_send_optimistic(self.uniffiClonePointer(), + FfiConverterData.lower(contentBytes), $0) + }) + } + open func stream(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser { return try await uniffiRustCallAsync( @@ -1703,6 +1718,113 @@ public func FfiConverterTypeFfiStreamCloser_lower(_ value: FfiStreamCloser) -> U return FfiConverterTypeFfiStreamCloser.lower(value) } +public protocol FfiUnpublishedMessageProtocol: AnyObject { + func id() -> Data + + func publish() async throws +} + +open class FfiUnpublishedMessage: + FfiUnpublishedMessageProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // 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`. + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffiunpublishedmessage(self.pointer, $0) } + } + + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_xmtpv3_fn_free_ffiunpublishedmessage(pointer, $0) } + } + + open func id() -> Data { + return try! FfiConverterData.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffiunpublishedmessage_id(self.uniffiClonePointer(), $0) + }) + } + + open func publish() async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiunpublishedmessage_publish( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) + } +} + +public struct FfiConverterTypeFfiUnpublishedMessage: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = FfiUnpublishedMessage + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiUnpublishedMessage { + return FfiUnpublishedMessage(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiUnpublishedMessage) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiUnpublishedMessage { + 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: FfiUnpublishedMessage, 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 func FfiConverterTypeFfiUnpublishedMessage_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiUnpublishedMessage { + return try FfiConverterTypeFfiUnpublishedMessage.lift(pointer) +} + +public func FfiConverterTypeFfiUnpublishedMessage_lower(_ value: FfiUnpublishedMessage) -> UnsafeMutableRawPointer { + return FfiConverterTypeFfiUnpublishedMessage.lower(value) +} + public protocol FfiV2ApiClientProtocol: AnyObject { func batchQuery(req: FfiV2BatchQueryRequest) async throws -> FfiV2BatchQueryResponse @@ -4913,6 +5035,9 @@ private var initializationResult: InitializationResult { if uniffi_xmtpv3_checksum_method_ffigroup_send() != 37701 { return InitializationResult.apiChecksumMismatch } + if uniffi_xmtpv3_checksum_method_ffigroup_send_optimistic() != 22919 { + return InitializationResult.apiChecksumMismatch + } if uniffi_xmtpv3_checksum_method_ffigroup_stream() != 45558 { return InitializationResult.apiChecksumMismatch } @@ -4970,6 +5095,12 @@ private var initializationResult: InitializationResult { if uniffi_xmtpv3_checksum_method_ffistreamcloser_is_closed() != 62423 { return InitializationResult.apiChecksumMismatch } + if uniffi_xmtpv3_checksum_method_ffiunpublishedmessage_id() != 4148 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_method_ffiunpublishedmessage_publish() != 47708 { + return InitializationResult.apiChecksumMismatch + } if uniffi_xmtpv3_checksum_method_ffiv2apiclient_batch_query() != 26551 { return InitializationResult.apiChecksumMismatch } From f865b0865bf9d9a11a363a5d79ed654d1e0a31ae Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 8 Jul 2024 11:41:10 -0600 Subject: [PATCH 2/2] bump the checksum --- LibXMTP.podspec | 4 ++-- Package.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LibXMTP.podspec b/LibXMTP.podspec index d711bbc..a3c0d11 100644 --- a/LibXMTP.podspec +++ b/LibXMTP.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'LibXMTP' - s.version = '0.5.4-beta2' + s.version = '0.5.4-beta3' s.summary = 'XMTP shared Rust code that powers cross-platform SDKs' s.homepage = 'https://github.com/xmtp/libxmtp-swift' @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.platform = :ios, '14.0', :macos, '11.0' s.swift_version = '5.3' - s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-5c78fba/LibXMTPSwiftFFI.zip", :type => :zip } + s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-d4d8134/LibXMTPSwiftFFI.zip", :type => :zip } s.vendored_frameworks = 'LibXMTPSwiftFFI.xcframework' s.source_files = 'Sources/LibXMTP/**/*' end diff --git a/Package.swift b/Package.swift index 08eb8bb..630be64 100644 --- a/Package.swift +++ b/Package.swift @@ -27,8 +27,8 @@ let package = Package( ), .binaryTarget( name: "LibXMTPSwiftFFI", - url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-5c78fba/LibXMTPSwiftFFI.zip", - checksum: "eb967303095d389701f957c5fd9f2e72eafddd5ae71bdd249a6dab26dfc30fb9" + url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-d4d8134/LibXMTPSwiftFFI.zip", + checksum: "26b52514c78edc030c73d7a9b21d7b55c2d42342dce4c7fb5480f530ab3cca30" ), .testTarget(name: "LibXMTPTests", dependencies: ["LibXMTP"]), ]