Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQL App Group Crash #339

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Sources/XMTPiOS/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extension GenericErrorDescribing {
let .GroupMetadata(message),
let .Generic(message):
return message
case .GroupMutablePermissions(message: let message):
return message
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@insipx was able to mark this function as delicate to warn developers before using.

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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be any reason to mark this as delicate because if they try to reconnect a already connected database nothing bad should happen right?

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()
Expand Down
6 changes: 3 additions & 3 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
Loading