diff --git a/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt index dcbc0d9c1..f6bc98b03 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt @@ -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 { @@ -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) + } } diff --git a/library/src/main/java/org/xmtp/android/library/Contacts.kt b/library/src/main/java/org/xmtp/android/library/Contacts.kt index 26b7e36d8..cb447c9cd 100644 --- a/library/src/main/java/org/xmtp/android/library/Contacts.kt +++ b/library/src/main/java/org/xmtp/android/library/Contacts.kt @@ -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() @@ -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 }