Skip to content

Commit

Permalink
Merge pull request #45 from xmtp/np/update-optimistic-send
Browse files Browse the repository at this point in the history
Bump the libxmtp version
  • Loading branch information
nplasterer authored Jul 9, 2024
2 parents b19830d + 20272c3 commit c38c7be
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 123 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.5.4-beta3'
s.version = '0.5.4-beta4'
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, '14.0', :macos, '11.0'
s.swift_version = '5.3'

s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-d4d8134/LibXMTPSwiftFFI.zip", :type => :zip }
s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-ec1da4e/LibXMTPSwiftFFI.zip", :type => :zip }
s.vendored_frameworks = 'LibXMTPSwiftFFI.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-d4d8134/LibXMTPSwiftFFI.zip",
checksum: "26b52514c78edc030c73d7a9b21d7b55c2d42342dce4c7fb5480f530ab3cca30"
url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-ec1da4e/LibXMTPSwiftFFI.zip",
checksum: "67ab27c10b5242a8bf7db48f0827b19f752811bb2c051b0390b6075e8e7c3e87"
),
.testTarget(name: "LibXMTPTests", dependencies: ["LibXMTP"]),
]
Expand Down
4 changes: 2 additions & 2 deletions Sources/LibXMTP/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: d4d8134a
Version: ec1da4e6
Branch: main
Date: 2024-07-08 15:44:32 +0000
Date: 2024-07-09 15:32:56 +0000
148 changes: 31 additions & 117 deletions Sources/LibXMTP/xmtpv3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ public protocol FfiGroupProtocol: AnyObject {

func processStreamedGroupMessage(envelopeBytes: Data) async throws -> FfiMessage

/**
* Publish all unpublished messages
*/
func publishMessages() async throws

func removeAdmin(inboxId: String) async throws

func removeMembers(accountAddresses: [String]) async throws
Expand All @@ -754,7 +759,7 @@ public protocol FfiGroupProtocol: AnyObject {
/**
* send a message without immediately publishing to the delivery service.
*/
func sendOptimistic(contentBytes: Data) throws -> FfiUnpublishedMessage
func sendOptimistic(contentBytes: Data) throws -> Data

func stream(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser

Expand Down Expand Up @@ -991,6 +996,25 @@ open class FfiGroup:
)
}

/**
* Publish all unpublished messages
*/
open func publishMessages() async throws {
return
try await uniffiRustCallAsync(
rustFutureFunc: {
uniffi_xmtpv3_fn_method_ffigroup_publish_messages(
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
)
}

open func removeAdmin(inboxId: String) async throws {
return
try await uniffiRustCallAsync(
Expand Down Expand Up @@ -1079,8 +1103,8 @@ 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) {
open func sendOptimistic(contentBytes: Data) throws -> Data {
return try FfiConverterData.lift(rustCallWithError(FfiConverterTypeGenericError.lift) {
uniffi_xmtpv3_fn_method_ffigroup_send_optimistic(self.uniffiClonePointer(),
FfiConverterData.lower(contentBytes), $0)
})
Expand Down Expand Up @@ -1718,113 +1742,6 @@ 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

Expand Down Expand Up @@ -5020,6 +4937,9 @@ private var initializationResult: InitializationResult {
if uniffi_xmtpv3_checksum_method_ffigroup_process_streamed_group_message() != 19069 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_publish_messages() != 52808 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_remove_admin() != 57094 {
return InitializationResult.apiChecksumMismatch
}
Expand All @@ -5035,7 +4955,7 @@ private var initializationResult: InitializationResult {
if uniffi_xmtpv3_checksum_method_ffigroup_send() != 37701 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_send_optimistic() != 22919 {
if uniffi_xmtpv3_checksum_method_ffigroup_send_optimistic() != 13872 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_stream() != 45558 {
Expand Down Expand Up @@ -5095,12 +5015,6 @@ 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
}
Expand Down

0 comments on commit c38c7be

Please sign in to comment.