diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt index 8cfb1a57a..c6aacc425 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt @@ -855,6 +855,7 @@ class ConversationTest { val caroConversation = bobClient.conversations.newConversation(fixtures.caro.walletAddress) bobClient.contacts.refreshConsentList() + Thread.sleep(1000) assertEquals(bobClient.contacts.consentList.entries.size, 2) assertTrue(bobConversation.consentState() == ConsentState.ALLOWED) assertTrue(caroConversation.consentState() == ConsentState.ALLOWED) diff --git a/library/src/main/java/org/xmtp/android/library/ApiClient.kt b/library/src/main/java/org/xmtp/android/library/ApiClient.kt index 33585245e..283f15f5b 100644 --- a/library/src/main/java/org/xmtp/android/library/ApiClient.kt +++ b/library/src/main/java/org/xmtp/android/library/ApiClient.kt @@ -129,20 +129,25 @@ data class GRPCApiClient( * It yields all the envelopes in the query using the paging info * from the prior response to fetch the next page. */ - override suspend fun envelopes(topic: String, pagination: Pagination?): List { + override suspend fun envelopes( + topic: String, + pagination: Pagination?, + ): List { var envelopes: MutableList = mutableListOf() var hasNextPage = true var cursor: Cursor? = null while (hasNextPage) { - val response = query(topic = topic, pagination = pagination, cursor = cursor) + val response = + query(topic = topic, pagination = pagination, cursor = cursor) envelopes.addAll(response.envelopesList) cursor = response.pagingInfo.cursor hasNextPage = response.envelopesList.isNotEmpty() && response.pagingInfo.hasCursor() - if (pagination?.limit != null && envelopes.size >= pagination.limit) { + if (pagination?.limit != null && pagination.limit <= 100 && envelopes.size >= pagination.limit) { envelopes = envelopes.take(pagination.limit).toMutableList() break } } + return envelopes } 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 a11960556..edadf7422 100644 --- a/library/src/main/java/org/xmtp/android/library/Contacts.kt +++ b/library/src/main/java/org/xmtp/android/library/Contacts.kt @@ -70,9 +70,11 @@ class ConsentList( Topic.preferenceList(identifier).description, Pagination( after = lastFetched, - direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING + direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING, + limit = 500 ), ) + lastFetched = newDate val preferences: MutableList = mutableListOf() for (envelope in envelopes) { diff --git a/library/src/main/java/org/xmtp/android/library/messages/PagingInfo.kt b/library/src/main/java/org/xmtp/android/library/messages/PagingInfo.kt index 6f3f5dc3b..2c6d3938c 100644 --- a/library/src/main/java/org/xmtp/android/library/messages/PagingInfo.kt +++ b/library/src/main/java/org/xmtp/android/library/messages/PagingInfo.kt @@ -16,35 +16,13 @@ data class Pagination( ) { val pagingInfo: PagingInfo get() { - return PagingInfo.newBuilder().also { - if (limit != null) { - it.limit = limit + return PagingInfo.newBuilder().also { page -> + limit?.let { + page.limit = it } if (direction != null) { - it.direction = direction + page.direction = direction } }.build() } } - -class PagingInfoBuilder { - companion object { - fun buildFromPagingInfo( - limit: Int? = null, - cursor: PagingInfoCursor? = null, - direction: PagingInfoSortDirection? = null, - ): PagingInfo { - return PagingInfo.newBuilder().also { - if (limit != null) { - it.limit = limit - } - if (cursor != null) { - it.cursor = cursor - } - if (direction != null) { - it.direction = direction - } - }.build() - } - } -}