Skip to content

Commit 5ca559a

Browse files
Merge branch 'master' of github.com:prose-im/prose-wrapper-swift
2 parents e434f7b + 6cb29e3 commit 5ca559a

File tree

4 files changed

+116
-18
lines changed

4 files changed

+116
-18
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ let package = Package(
1111
.target(name: "ProseCoreFFI", dependencies: ["ProseCoreFFIFFI"]),
1212
.binaryTarget(
1313
name: "ProseCoreFFIFFI",
14-
url: "https://github.com/prose-im/prose-wrapper-swift/releases/download/0.9.0/ProseCoreFFI.xcframework.zip",
15-
checksum: "a8c741cf68e5bc41fdaf7a51d363649b4d13c8a5ba26bd79d7f55a331265ddfe"
14+
url: "https://github.com/prose-im/prose-wrapper-swift/releases/download/0.13.0/ProseCoreFFI.xcframework.zip",
15+
checksum: "cef697da3a3c8809b9eb1279d9dbd1435513eadfcb53c0113f590d86b78b834e"
1616
),
1717
]
1818
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// This file is part of prose-app-macos.
3+
// Copyright (c) 2023 Prose Foundation
4+
//
5+
6+
import Foundation
7+
8+
extension ClientError: LocalizedError {
9+
/// - Important: ``ClientError`` is not localized.
10+
public var errorDescription: String? {
11+
switch self {
12+
case .Generic(let msg):
13+
return msg
14+
}
15+
}
16+
}

Sources/ProseCoreFFI/ProseCoreFFI.swift

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ public func FfiConverterTypeAccountBookmarksClient_lower(_ value: AccountBookmar
454454
}
455455

456456
public protocol ClientProtocol {
457-
func connect(password: String) async throws
457+
func connect(password: String, availability: Availability, status: String?) async throws
458+
func deleteProfile() async throws
458459
func disconnect() async throws
459460
func jid() -> FullJid
460461
func loadAccountSettings() async throws -> AccountSettings
@@ -465,7 +466,7 @@ public protocol ClientProtocol {
465466
func loadLatestMessages(from: BareJid, since: MessageId?, loadFromServer: Bool) async throws -> [Message]
466467
func loadMessagesBefore(from: BareJid, before: MessageId) async throws -> MessagesPage
467468
func loadMessagesWithIds(conversation: BareJid, ids: [MessageId]) async throws -> [Message]
468-
func loadProfile(from: BareJid, cachePolicy: CachePolicy) async throws -> UserProfile
469+
func loadProfile(from: BareJid, cachePolicy: CachePolicy) async throws -> UserProfile?
469470
func retractMessage(conversation: BareJid, id: MessageId) async throws
470471
func saveAccountSettings(settings: AccountSettings) async throws
471472
func saveAvatar(imagePath: PathBuf) async throws
@@ -502,11 +503,13 @@ public class Client: ClientProtocol {
502503
try! rustCall { ffi_prose_core_ffi_d633_Client_object_free(pointer, $0) }
503504
}
504505

505-
public func connect(password: String) async throws {
506+
public func connect(password: String, availability: Availability, status: String?) async throws {
506507
let future = try
507508
rustCallWithError(FfiConverterTypeConnectionError.self) {
508-
_uniffi_prose_core_ffi_impl_Client_connect_5f8b(self.pointer,
509-
FfiConverterString.lower(password), $0)
509+
_uniffi_prose_core_ffi_impl_Client_connect_654e(self.pointer,
510+
FfiConverterString.lower(password),
511+
FfiConverterTypeAvailability.lower(availability),
512+
FfiConverterOptionString.lower(status), $0)
510513
}
511514

512515
return try await withCheckedThrowingContinuation { continuation in
@@ -515,6 +518,18 @@ public class Client: ClientProtocol {
515518
}
516519
}
517520

521+
public func deleteProfile() async throws {
522+
let future = try
523+
rustCallWithError(FfiConverterTypeClientError.self) {
524+
_uniffi_prose_core_ffi_impl_Client_delete_profile_4021(self.pointer, $0)
525+
}
526+
527+
return try await withCheckedThrowingContinuation { continuation in
528+
let env = Unmanaged.passRetained(_UniFFI_Client_DeleteProfile_Env(rustyFuture: future, continuation: continuation))
529+
_UniFFI_Client_DeleteProfile_waker(raw_env: env.toOpaque())
530+
}
531+
}
532+
518533
public func disconnect() async throws {
519534
let future = try
520535
rustCallWithError(FfiConverterTypeClientError.self) {
@@ -644,10 +659,10 @@ public class Client: ClientProtocol {
644659
}
645660
}
646661

647-
public func loadProfile(from: BareJid, cachePolicy: CachePolicy) async throws -> UserProfile {
662+
public func loadProfile(from: BareJid, cachePolicy: CachePolicy) async throws -> UserProfile? {
648663
let future = try
649664
rustCallWithError(FfiConverterTypeClientError.self) {
650-
_uniffi_prose_core_ffi_impl_Client_load_profile_420c(self.pointer,
665+
_uniffi_prose_core_ffi_impl_Client_load_profile_4d8b(self.pointer,
651666
FfiConverterTypeBareJid.lower(from),
652667
FfiConverterTypeCachePolicy.lower(cachePolicy), $0)
653668
}
@@ -809,7 +824,7 @@ private class _UniFFI_Client_Connect_Env {
809824

810825
deinit {
811826
try! rustCall {
812-
_uniffi_prose_core_ffi_impl_Client_connect_5f8b_drop(self.rustFuture, $0)
827+
_uniffi_prose_core_ffi_impl_Client_connect_654e_drop(self.rustFuture, $0)
813828
}
814829
}
815830
}
@@ -821,7 +836,7 @@ private func _UniFFI_Client_Connect_waker(raw_env: UnsafeMutableRawPointer?) {
821836
let polledResult = UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: 0)
822837
do {
823838
let isReady = try rustCallWithError(FfiConverterTypeConnectionError.self) {
824-
_uniffi_prose_core_ffi_impl_Client_connect_5f8b_poll(
839+
_uniffi_prose_core_ffi_impl_Client_connect_654e_poll(
825840
env_ref.rustFuture,
826841
_UniFFI_Client_Connect_waker,
827842
env.toOpaque(),
@@ -843,6 +858,51 @@ private func _UniFFI_Client_Connect_waker(raw_env: UnsafeMutableRawPointer?) {
843858
}
844859
}
845860

861+
private class _UniFFI_Client_DeleteProfile_Env {
862+
var rustFuture: OpaquePointer
863+
var continuation: CheckedContinuation<Void, Error>
864+
865+
init(rustyFuture: OpaquePointer, continuation: CheckedContinuation<Void, Error>) {
866+
rustFuture = rustyFuture
867+
self.continuation = continuation
868+
}
869+
870+
deinit {
871+
try! rustCall {
872+
_uniffi_prose_core_ffi_impl_Client_delete_profile_4021_drop(self.rustFuture, $0)
873+
}
874+
}
875+
}
876+
877+
private func _UniFFI_Client_DeleteProfile_waker(raw_env: UnsafeMutableRawPointer?) {
878+
Task {
879+
let env = Unmanaged<_UniFFI_Client_DeleteProfile_Env>.fromOpaque(raw_env!)
880+
let env_ref = env.takeUnretainedValue()
881+
let polledResult = UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: 0)
882+
do {
883+
let isReady = try rustCallWithError(FfiConverterTypeClientError.self) {
884+
_uniffi_prose_core_ffi_impl_Client_delete_profile_4021_poll(
885+
env_ref.rustFuture,
886+
_UniFFI_Client_DeleteProfile_waker,
887+
env.toOpaque(),
888+
polledResult,
889+
$0
890+
)
891+
}
892+
893+
if isReady {
894+
env_ref.continuation.resume(returning: ())
895+
polledResult.deallocate()
896+
env.release()
897+
}
898+
} catch {
899+
env_ref.continuation.resume(throwing: error)
900+
polledResult.deallocate()
901+
env.release()
902+
}
903+
}
904+
}
905+
846906
private class _UniFFI_Client_Disconnect_Env {
847907
var rustFuture: OpaquePointer
848908
var continuation: CheckedContinuation<Void, Error>
@@ -1250,16 +1310,16 @@ private func _UniFFI_Client_LoadMessagesWithIds_waker(raw_env: UnsafeMutableRawP
12501310

12511311
private class _UniFFI_Client_LoadProfile_Env {
12521312
var rustFuture: OpaquePointer
1253-
var continuation: CheckedContinuation<UserProfile, Error>
1313+
var continuation: CheckedContinuation<UserProfile?, Error>
12541314

1255-
init(rustyFuture: OpaquePointer, continuation: CheckedContinuation<UserProfile, Error>) {
1315+
init(rustyFuture: OpaquePointer, continuation: CheckedContinuation<UserProfile?, Error>) {
12561316
rustFuture = rustyFuture
12571317
self.continuation = continuation
12581318
}
12591319

12601320
deinit {
12611321
try! rustCall {
1262-
_uniffi_prose_core_ffi_impl_Client_load_profile_420c_drop(self.rustFuture, $0)
1322+
_uniffi_prose_core_ffi_impl_Client_load_profile_4d8b_drop(self.rustFuture, $0)
12631323
}
12641324
}
12651325
}
@@ -1271,7 +1331,7 @@ private func _UniFFI_Client_LoadProfile_waker(raw_env: UnsafeMutableRawPointer?)
12711331
let polledResult = UnsafeMutablePointer<RustBuffer>.allocate(capacity: 1)
12721332
do {
12731333
let isReady = try rustCallWithError(FfiConverterTypeClientError.self) {
1274-
_uniffi_prose_core_ffi_impl_Client_load_profile_420c_poll(
1334+
_uniffi_prose_core_ffi_impl_Client_load_profile_4d8b_poll(
12751335
env_ref.rustFuture,
12761336
_UniFFI_Client_LoadProfile_waker,
12771337
env.toOpaque(),
@@ -1281,7 +1341,7 @@ private func _UniFFI_Client_LoadProfile_waker(raw_env: UnsafeMutableRawPointer?)
12811341
}
12821342

12831343
if isReady {
1284-
env_ref.continuation.resume(returning: try! FfiConverterTypeUserProfile.lift(polledResult.move()))
1344+
env_ref.continuation.resume(returning: try! FfiConverterOptionTypeUserProfile.lift(polledResult.move()))
12851345
polledResult.deallocate()
12861346
env.release()
12871347
}
@@ -3224,6 +3284,27 @@ private struct FfiConverterOptionTypeAddress: FfiConverterRustBuffer {
32243284
}
32253285
}
32263286

3287+
private struct FfiConverterOptionTypeUserProfile: FfiConverterRustBuffer {
3288+
typealias SwiftType = UserProfile?
3289+
3290+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
3291+
guard let value = value else {
3292+
writeInt(&buf, Int8(0))
3293+
return
3294+
}
3295+
writeInt(&buf, Int8(1))
3296+
FfiConverterTypeUserProfile.write(value, into: &buf)
3297+
}
3298+
3299+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
3300+
switch try readInt(&buf) as Int8 {
3301+
case 0: return nil
3302+
case 1: return try FfiConverterTypeUserProfile.read(from: &buf)
3303+
default: throw UniffiInternalError.unexpectedOptionalTag
3304+
}
3305+
}
3306+
}
3307+
32273308
private struct FfiConverterOptionCallbackInterfaceClientDelegate: FfiConverterRustBuffer {
32283309
typealias SwiftType = ClientDelegate?
32293310

@@ -3651,7 +3732,7 @@ public struct FfiConverterTypeUrl: FfiConverter {
36513732
}
36523733

36533734
public static func write(_ value: Url, into buf: inout [UInt8]) {
3654-
let builtinValue = value.path
3735+
let builtinValue = value.absoluteString
36553736
return FfiConverterString.write(builtinValue, into: &buf)
36563737
}
36573738

@@ -3661,7 +3742,7 @@ public struct FfiConverterTypeUrl: FfiConverter {
36613742
}
36623743

36633744
public static func lower(_ value: Url) -> RustBuffer {
3664-
let builtinValue = value.path
3745+
let builtinValue = value.absoluteString
36653746
return FfiConverterString.lower(builtinValue)
36663747
}
36673748
}

scripts/build-core-client.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ generate_swift_package() {
132132
cp "${interface_tmp_dir}/${CORE_LIB_MODULE_NAME}.swift" "${SPM_BUILD_FOLDER}/${SWIFT_LIB_NAME}/Sources/${SWIFT_LIB_NAME}"
133133
cp "${SOURCES_FOLDER}/${SWIFT_LIB_NAME}/Emoji.swift" "${SPM_BUILD_FOLDER}/${SWIFT_LIB_NAME}/Sources/${SWIFT_LIB_NAME}"
134134
cp "${SOURCES_FOLDER}/${SWIFT_LIB_NAME}/MessageId.swift" "${SPM_BUILD_FOLDER}/${SWIFT_LIB_NAME}/Sources/${SWIFT_LIB_NAME}"
135+
cp "${SOURCES_FOLDER}/${SWIFT_LIB_NAME}/Errors+Description.swift" "${SPM_BUILD_FOLDER}/${SWIFT_LIB_NAME}/Sources/${SWIFT_LIB_NAME}"
135136

136137
xcrun xcodebuild "${xcodebuild_args[@]}"
137138

0 commit comments

Comments
 (0)