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

feat: Pagination on Consent Refresh #216

Closed
wants to merge 1 commit into from
Closed
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 @@ -6,6 +6,7 @@ import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.messages.walletAddress
import java.util.Date

@RunWith(AndroidJUnit4::class)
class ContactsTest {
Expand Down Expand Up @@ -69,4 +70,25 @@ class ContactsTest {
result = contacts.isDenied(fixtures.alice.walletAddress)
assert(result)
}

@Test
fun testRefreshConsentListPagination() {
val fixtures = fixtures()
val contacts = fixtures.bobClient.contacts
val aliceAddress = fixtures.alice.walletAddress
runBlocking {
contacts.deny(listOf(aliceAddress))
}
val date = Date()
val result: ConsentList
runBlocking {
result = contacts.consentList.load(date)
}
assert(result.entries[ConsentListEntry.address(aliceAddress).key]?.consentType == null)
val allResult: ConsentList
runBlocking {
allResult = contacts.consentList.load()
}
assert(allResult.entries[ConsentListEntry.address(aliceAddress).key]?.consentType != null)
}
}
8 changes: 4 additions & 4 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class ConsentList(val client: Client) {
)

@OptIn(ExperimentalUnsignedTypes::class)
suspend fun load(): ConsentList {
suspend fun load(afterDate: Date? = null): ConsentList {
val envelopes =
client.apiClient.envelopes(
Topic.preferenceList(identifier).description,
Pagination(direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING),
Pagination(direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING, after = afterDate),
)
val consentList = ConsentList(client)
val preferences: MutableList<PrivatePreferencesAction> = mutableListOf()
Expand Down Expand Up @@ -203,9 +203,9 @@ data class Contacts(
) {
var consentList: ConsentList = ConsentList(client)

fun refreshConsentList(): ConsentList {
fun refreshConsentList(afterDate: Date? = null): ConsentList {
runBlocking {
consentList = ConsentList(client).load()
consentList = ConsentList(client).load(afterDate)
}
return consentList
}
Expand Down
Loading