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

Add ability to sync all groups at once #392

Merged
merged 1 commit into from
Aug 22, 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
7 changes: 7 additions & 0 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down
Loading