Skip to content

Commit

Permalink
add ability to sync all groups (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer authored Aug 22, 2024
1 parent 2b3e409 commit 2e34f53
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit 2e34f53

Please sign in to comment.