diff --git a/Sources/XMTPiOS/Conversations.swift b/Sources/XMTPiOS/Conversations.swift index b0c34042..5cf8e419 100644 --- a/Sources/XMTPiOS/Conversations.swift +++ b/Sources/XMTPiOS/Conversations.swift @@ -103,6 +103,13 @@ public actor Conversations { } try await v3Client.conversations().sync() } + + public func syncAllGroups() async throws { + guard let v3Client = client.v3Client else { + return + } + try await v3Client.conversations().syncAllGroups() + } public func groups(createdAfter: Date? = nil, createdBefore: Date? = nil, limit: Int? = nil) async throws -> [Group] { guard let v3Client = client.v3Client else { diff --git a/Tests/XMTPTests/GroupTests.swift b/Tests/XMTPTests/GroupTests.swift index 1eb3bd97..9628d546 100644 --- a/Tests/XMTPTests/GroupTests.swift +++ b/Tests/XMTPTests/GroupTests.swift @@ -838,6 +838,34 @@ class GroupTests: XCTestCase { XCTAssertEqual(preparedMessageId, messages.first!.id) } + func testCanSyncManyGroupsInUnderASecond() async throws { + let fixtures = try await localFixtures() + var groups: [Group] = [] + + for _ in 0..<100 { + var group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address]) + groups.append(group) + } + try await fixtures.bobClient.conversations.sync() + let bobGroup = try fixtures.bobClient.findGroup(groupId: groups[0].id) + try await groups[0].send(content: "hi") + let messageCount = try await bobGroup!.messages().count + XCTAssertEqual(messageCount, 0) + do { + let start = Date() + let _ = try await fixtures.bobClient.conversations.syncAllGroups() + let end = Date() + print(end.timeIntervalSince(start)) + XCTAssert(end.timeIntervalSince(start) < 1) + } catch { + print("Failed to list groups members: \(error)") + throw error // Rethrow the error to fail the test if group creation fails + } + + let messageCount2 = try await bobGroup!.messages().count + XCTAssertEqual(messageCount2, 1) + } + func testCanListManyMembersInParallelInUnderASecond() async throws { let fixtures = try await localFixtures() var groups: [Group] = []