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 #290

Merged
merged 1 commit into from
Aug 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,49 @@ class GroupTest {

assertEquals(preparedMessageId, message.id)
}

@Test
fun testSyncsAllGroupsInParallel() {
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
)
)
}
val boGroup2 = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
)
)
}
runBlocking { alixClient.conversations.syncGroups() }
val alixGroup: Group = alixClient.findGroup(boGroup.id)!!
val alixGroup2: Group = alixClient.findGroup(boGroup2.id)!!

assertEquals(alixGroup.messages().size, 0)
assertEquals(alixGroup2.messages().size, 0)

runBlocking {
boGroup.send("hi")
boGroup2.send("hi")
alixClient.conversations.syncAllGroups()
}

assertEquals(alixGroup.messages().size, 1)
assertEquals(alixGroup2.messages().size, 1)

runBlocking {
boGroup2.removeMembers(listOf(alix.walletAddress))
boGroup.send("hi")
boGroup.send("hi")
boGroup2.send("hi")
boGroup2.send("hi")
alixClient.conversations.syncAllGroups()
}

assertEquals(alixGroup.messages().size, 3)
assertEquals(alixGroup2.messages().size, 2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,16 @@ data class Conversations(
return Group(client, group)
}

// Sync from the network the latest list of groups
suspend fun syncGroups() {
libXMTPConversations?.sync()
}

// Sync all existing local groups data from the network (Note: call syncGroups() first to get the latest list of groups)
suspend fun syncAllGroups() {
libXMTPConversations?.syncAllGroups()
}

suspend fun listGroups(
after: Date? = null,
before: Date? = null,
Expand Down
Loading