From ce64fc4e199e592a318ae5644cefad2e9c7be2aa Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Mon, 26 Aug 2024 11:29:11 -0700 Subject: [PATCH] return number of active groups synced from sync all groups function. possible fork fixes --- Package.resolved | 4 ++-- Package.swift | 2 +- Sources/XMTPiOS/Conversations.swift | 6 +++--- Tests/XMTPTests/GroupTests.swift | 19 ++++++++++++++++++- XMTP.podspec | 4 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Package.resolved b/Package.resolved index 1447583c..03d36b46 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift.git", "state" : { - "revision" : "6ddc5a583663560698d66a7f99852ccb093cf4a5", - "version" : "0.5.7-beta2" + "revision" : "c27b586925714a253e5e9b3875788571552f46d6", + "version" : "0.5.8-beta1" } }, { diff --git a/Package.swift b/Package.swift index 4f2a16d0..6ca0524b 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.git", exact: "0.5.8-beta0"), + .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "0.5.8-beta1"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/XMTPiOS/Conversations.swift b/Sources/XMTPiOS/Conversations.swift index 5cf8e419..4cb0d1ea 100644 --- a/Sources/XMTPiOS/Conversations.swift +++ b/Sources/XMTPiOS/Conversations.swift @@ -104,11 +104,11 @@ public actor Conversations { try await v3Client.conversations().sync() } - public func syncAllGroups() async throws { + public func syncAllGroups() async throws -> UInt32 { guard let v3Client = client.v3Client else { - return + return 0 } - try await v3Client.conversations().syncAllGroups() + return try await v3Client.conversations().syncAllGroups() } public func groups(createdAfter: Date? = nil, createdBefore: Date? = nil, limit: Int? = nil) async throws -> [Group] { diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index 9628d546..5ea5ec48 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -853,10 +853,11 @@ class GroupTests: XCTestCase { XCTAssertEqual(messageCount, 0) do { let start = Date() - let _ = try await fixtures.bobClient.conversations.syncAllGroups() + let numGroupsSynced = try await fixtures.bobClient.conversations.syncAllGroups() let end = Date() print(end.timeIntervalSince(start)) XCTAssert(end.timeIntervalSince(start) < 1) + XCTAssert(numGroupsSynced == 100) } catch { print("Failed to list groups members: \(error)") throw error // Rethrow the error to fail the test if group creation fails @@ -864,6 +865,22 @@ class GroupTests: XCTestCase { let messageCount2 = try await bobGroup!.messages().count XCTAssertEqual(messageCount2, 1) + + for aliceConv in try await fixtures.aliceClient.conversations.list(includeGroups: true) { + guard case let .group(aliceGroup) = aliceConv else { + XCTFail("failed converting conversation to group") + return + } + try await aliceGroup.removeMembers(addresses: [fixtures.bobClient.address]) + } + + // first syncAllGroups after removal still sync groups in order to process the removal + var numGroupsSynced = try await fixtures.bobClient.conversations.syncAllGroups() + XCTAssert(numGroupsSynced == 100) + + // next syncAllGroups only will sync active groups + numGroupsSynced = try await fixtures.bobClient.conversations.syncAllGroups() + XCTAssert(numGroupsSynced == 0) } func testCanListManyMembersInParallelInUnderASecond() async throws { diff --git a/XMTP.podspec b/XMTP.podspec index 04c6fc6d..6cac320d 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.14.8" + spec.version = "0.14.9" 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.5.8-beta0' + spec.dependency 'LibXMTP', '= 0.5.8-beta1' end