Skip to content

Commit

Permalink
Merge pull request #70 from xmtp/np/stream-groups-logging
Browse files Browse the repository at this point in the history
Expose timestamp on installation and make members async
  • Loading branch information
nplasterer authored Sep 26, 2024
2 parents 9398f55 + 0d96170 commit 859333f
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 19 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.8-beta6'
s.version = '0.5.8-beta7'
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-34d3249/LibXMTPSwiftFFI.zip", :type => :zip }
s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-4f529ae/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-34d3249/LibXMTPSwiftFFI.zip",
checksum: "8efa8d3ce01232a6308aaf26a2fbf5dc1e509a3cddfe32a79e6a487bf11a158d"
url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-4f529ae/LibXMTPSwiftFFI.zip",
checksum: "511855c643ba5c0e2f719cad5a39450a472c5b6e30d56e4faf6cd7f2b43d49f9"
),
.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: 34d32499
Version: 4f529aeb
Branch: main
Date: 2024-09-19 21:05:16 +0000
Date: 2024-09-26 04:05:26 +0000
131 changes: 118 additions & 13 deletions Sources/LibXMTP/xmtpv3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ public protocol FfiGroupProtocol: AnyObject {

func isSuperAdmin(inboxId: String) throws -> Bool

func listMembers() throws -> [FfiGroupMember]
func listMembers() async throws -> [FfiGroupMember]

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

Expand Down Expand Up @@ -1002,10 +1002,20 @@ open class FfiGroup:
})
}

open func listMembers() throws -> [FfiGroupMember] {
return try FfiConverterSequenceTypeFfiGroupMember.lift(rustCallWithError(FfiConverterTypeGenericError.lift) {
uniffi_xmtpv3_fn_method_ffigroup_list_members(self.uniffiClonePointer(), $0)
})
open func listMembers() async throws -> [FfiGroupMember] {
return
try await uniffiRustCallAsync(
rustFutureFunc: {
uniffi_xmtpv3_fn_method_ffigroup_list_members(
self.uniffiClonePointer()
)
},
pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer,
completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer,
freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer,
liftFunc: FfiConverterSequenceTypeFfiGroupMember.lift,
errorHandler: FfiConverterTypeGenericError.lift
)
}

open func processStreamedGroupMessage(envelopeBytes: Data) async throws -> FfiMessage {
Expand Down Expand Up @@ -2875,15 +2885,15 @@ public func FfiConverterTypeFfiGroupMember_lower(_ value: FfiGroupMember) -> Rus
public struct FfiInboxState {
public var inboxId: String
public var recoveryAddress: String
public var installationIds: [Data]
public var installations: [FfiInstallation]
public var accountAddresses: [String]

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(inboxId: String, recoveryAddress: String, installationIds: [Data], accountAddresses: [String]) {
public init(inboxId: String, recoveryAddress: String, installations: [FfiInstallation], accountAddresses: [String]) {
self.inboxId = inboxId
self.recoveryAddress = recoveryAddress
self.installationIds = installationIds
self.installations = installations
self.accountAddresses = accountAddresses
}
}
Expand All @@ -2896,7 +2906,7 @@ extension FfiInboxState: Equatable, Hashable {
if lhs.recoveryAddress != rhs.recoveryAddress {
return false
}
if lhs.installationIds != rhs.installationIds {
if lhs.installations != rhs.installations {
return false
}
if lhs.accountAddresses != rhs.accountAddresses {
Expand All @@ -2908,7 +2918,7 @@ extension FfiInboxState: Equatable, Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(inboxId)
hasher.combine(recoveryAddress)
hasher.combine(installationIds)
hasher.combine(installations)
hasher.combine(accountAddresses)
}
}
Expand All @@ -2919,15 +2929,15 @@ public struct FfiConverterTypeFfiInboxState: FfiConverterRustBuffer {
try FfiInboxState(
inboxId: FfiConverterString.read(from: &buf),
recoveryAddress: FfiConverterString.read(from: &buf),
installationIds: FfiConverterSequenceData.read(from: &buf),
installations: FfiConverterSequenceTypeFfiInstallation.read(from: &buf),
accountAddresses: FfiConverterSequenceString.read(from: &buf)
)
}

public static func write(_ value: FfiInboxState, into buf: inout [UInt8]) {
FfiConverterString.write(value.inboxId, into: &buf)
FfiConverterString.write(value.recoveryAddress, into: &buf)
FfiConverterSequenceData.write(value.installationIds, into: &buf)
FfiConverterSequenceTypeFfiInstallation.write(value.installations, into: &buf)
FfiConverterSequenceString.write(value.accountAddresses, into: &buf)
}
}
Expand All @@ -2940,6 +2950,58 @@ public func FfiConverterTypeFfiInboxState_lower(_ value: FfiInboxState) -> RustB
return FfiConverterTypeFfiInboxState.lower(value)
}

public struct FfiInstallation {
public var id: Data
public var clientTimestampNs: UInt64?

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(id: Data, clientTimestampNs: UInt64?) {
self.id = id
self.clientTimestampNs = clientTimestampNs
}
}

extension FfiInstallation: Equatable, Hashable {
public static func == (lhs: FfiInstallation, rhs: FfiInstallation) -> Bool {
if lhs.id != rhs.id {
return false
}
if lhs.clientTimestampNs != rhs.clientTimestampNs {
return false
}
return true
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(clientTimestampNs)
}
}

public struct FfiConverterTypeFfiInstallation: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiInstallation {
return
try FfiInstallation(
id: FfiConverterData.read(from: &buf),
clientTimestampNs: FfiConverterOptionUInt64.read(from: &buf)
)
}

public static func write(_ value: FfiInstallation, into buf: inout [UInt8]) {
FfiConverterData.write(value.id, into: &buf)
FfiConverterOptionUInt64.write(value.clientTimestampNs, into: &buf)
}
}

public func FfiConverterTypeFfiInstallation_lift(_ buf: RustBuffer) throws -> FfiInstallation {
return try FfiConverterTypeFfiInstallation.lift(buf)
}

public func FfiConverterTypeFfiInstallation_lower(_ value: FfiInstallation) -> RustBuffer {
return FfiConverterTypeFfiInstallation.lower(value)
}

public struct FfiListConversationsOptions {
public var createdAfterNs: Int64?
public var createdBeforeNs: Int64?
Expand Down Expand Up @@ -4680,6 +4742,27 @@ extension FfiConverterCallbackInterfaceFfiV2SubscriptionCallback: FfiConverter {
}
}

private struct FfiConverterOptionUInt64: FfiConverterRustBuffer {
typealias SwiftType = UInt64?

public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterUInt64.write(value, into: &buf)
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterUInt64.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}

private struct FfiConverterOptionInt64: FfiConverterRustBuffer {
typealias SwiftType = Int64?

Expand Down Expand Up @@ -5022,6 +5105,28 @@ private struct FfiConverterSequenceTypeFfiGroupMember: FfiConverterRustBuffer {
}
}

private struct FfiConverterSequenceTypeFfiInstallation: FfiConverterRustBuffer {
typealias SwiftType = [FfiInstallation]

public static func write(_ value: [FfiInstallation], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeFfiInstallation.write(item, into: &buf)
}
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [FfiInstallation] {
let len: Int32 = try readInt(&buf)
var seq = [FfiInstallation]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
try seq.append(FfiConverterTypeFfiInstallation.read(from: &buf))
}
return seq
}
}

private struct FfiConverterSequenceTypeFfiMessage: FfiConverterRustBuffer {
typealias SwiftType = [FfiMessage]

Expand Down Expand Up @@ -5478,7 +5583,7 @@ private var initializationResult: InitializationResult = {
if uniffi_xmtpv3_checksum_method_ffigroup_is_super_admin() != 61614 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_list_members() != 61034 {
if uniffi_xmtpv3_checksum_method_ffigroup_list_members() != 3945 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffigroup_process_streamed_group_message() != 19069 {
Expand Down

0 comments on commit 859333f

Please sign in to comment.