From d36194c5496a395ce0b39863441a1d95bb8836db Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 23 May 2024 16:10:27 -0700 Subject: [PATCH 1/3] bump the ios version --- Package.swift | 2 +- XMTP.podspec | 4 ++-- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 5c7f3fd3..4466e285 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "0.12.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.4-beta5"), + .package(url: "https://github.com/xmtp/libxmtp-swift", exact: "0.4.4-beta6"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/XMTP.podspec b/XMTP.podspec index e5e95fb3..49a5d57a 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.10.11" + spec.version = "0.10.12" spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results. @@ -44,5 +44,5 @@ Pod::Spec.new do |spec| spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift", "= 0.12.0" - spec.dependency 'LibXMTP', '= 0.4.4-beta5' + spec.dependency 'LibXMTP', '= 0.4.4-beta6' end diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1d8b0f1f..8a9eda41 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift", "state" : { - "revision" : "f2b73d14be21b64feecfa70c789b3302525975ab", - "version" : "0.4.4-beta5" + "revision" : "11ac13baf3b2d36571a8ad5b0d8bda3017635563", + "version" : "0.4.4-beta6" } }, { From 5b8fcddca974efeec6181fb74da2af89c7f8fad9 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 23 May 2024 16:18:03 -0700 Subject: [PATCH 2/3] add functions to disconnect and reconnect the database --- Sources/XMTPiOS/Client.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 22eb5d82..30da8638 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -462,6 +462,21 @@ public final class Client { let fm = FileManager.default try fm.removeItem(atPath: dbPath) } + + @available(*, deprecated, message: "This function is delicate and should be used with caution. App will error if database not properly reconnected. See: reconnectLocalDatabase()") + public func dropLocalDatabaseConnection() throws { + guard let client = v3Client else { + throw ClientError.noV3Client("Error no V3 client initialized") + } + try client.releaseDbConnection() + } + + public func reconnectLocalDatabase() async throws { + guard let client = v3Client else { + throw ClientError.noV3Client("Error no V3 client initialized") + } + try await client.dbReconnect() + } func getUserContact(peerAddress: String) async throws -> ContactBundle? { let peerAddress = EthereumAddress(peerAddress).toChecksumAddress() From 9d826c170ec577bf86d3144ba325b212869a6633 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 23 May 2024 16:55:53 -0700 Subject: [PATCH 3/3] write a test for it --- Sources/XMTPiOS/ApiClient.swift | 2 ++ Sources/XMTPiOS/Group.swift | 6 +++--- Tests/XMTPTests/ClientTests.swift | 35 +++++++++++++++++++++++++++++++ Tests/XMTPTests/GroupTests.swift | 8 +++---- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Sources/XMTPiOS/ApiClient.swift b/Sources/XMTPiOS/ApiClient.swift index ab5a184c..37fca6d5 100644 --- a/Sources/XMTPiOS/ApiClient.swift +++ b/Sources/XMTPiOS/ApiClient.swift @@ -37,6 +37,8 @@ extension GenericErrorDescribing { let .GroupMetadata(message), let .Generic(message): return message + case .GroupMutablePermissions(message: let message): + return message } } } diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index d68bfb51..b638d940 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -71,9 +71,9 @@ public struct Group: Identifiable, Equatable, Hashable { return try metadata().creatorAccountAddress().lowercased() == client.address.lowercased() } - public func permissionLevel() throws -> GroupPermissions { - return try metadata().policyType() - } +// public func permissionLevel() throws -> GroupPermissions { +// return try metadata().policyType() +// } public func adminAddress() throws -> String { return try metadata().creatorAccountAddress() diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 23d58056..e5b3b0d6 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -194,6 +194,41 @@ class ClientTests: XCTestCase { groupCount = try await boClient.conversations.groups().count XCTAssertEqual(groupCount, 0) } + + func testCanDropReconnectDatabase() async throws { + let bo = try PrivateKey.generate() + let alix = try PrivateKey.generate() + var boClient = try await Client.create( + account: bo, + options: .init( + api: .init(env: .local, isSecure: false), + mlsAlpha: true + ) + ) + + let alixClient = try await Client.create( + account: alix, + options: .init( + api: .init(env: .local, isSecure: false), + mlsAlpha: true + ) + ) + + _ = try await boClient.conversations.newGroup(with: [alixClient.address]) + try await boClient.conversations.sync() + + var groupCount = try await boClient.conversations.groups().count + XCTAssertEqual(groupCount, 1) + + try boClient.dropLocalDatabaseConnection() + + await assertThrowsAsyncError(try await boClient.conversations.groups()) + + try await boClient.reconnectLocalDatabase() + + groupCount = try await boClient.conversations.groups().count + XCTAssertEqual(groupCount, 1) + } func testCanMessage() async throws { let fixtures = await fixtures() diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index abbabff4..0b24b1ee 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -110,8 +110,8 @@ class GroupTests: XCTestCase { XCTAssertEqual(aliceGroup.memberAddresses.count, 3) XCTAssertEqual(bobGroup.memberAddresses.count, 3) - XCTAssertEqual(try bobGroup.permissionLevel(), .everyoneIsAdmin) - XCTAssertEqual(try aliceGroup.permissionLevel(), .everyoneIsAdmin) +// XCTAssertEqual(try bobGroup.permissionLevel(), .everyoneIsAdmin) +// XCTAssertEqual(try aliceGroup.permissionLevel(), .everyoneIsAdmin) XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) XCTAssert(try bobGroup.isAdmin()) @@ -156,8 +156,8 @@ class GroupTests: XCTestCase { XCTAssertEqual(aliceGroup.memberAddresses.count, 2) XCTAssertEqual(bobGroup.memberAddresses.count, 2) - XCTAssertEqual(try bobGroup.permissionLevel(), .groupCreatorIsAdmin) - XCTAssertEqual(try aliceGroup.permissionLevel(), .groupCreatorIsAdmin) +// XCTAssertEqual(try bobGroup.permissionLevel(), .groupCreatorIsAdmin) +// XCTAssertEqual(try aliceGroup.permissionLevel(), .groupCreatorIsAdmin) XCTAssertEqual(try bobGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) XCTAssertEqual(try aliceGroup.adminAddress().lowercased(), fixtures.bobClient.address.lowercased()) XCTAssert(try bobGroup.isAdmin())