From ffa46fa39226dc7006a784da02e6e7043fad993e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 3 Jan 2024 13:09:39 -0800 Subject: [PATCH 1/3] fix consent only fetching first 100 entries --- .../xmtp/android/library/ConversationTest.kt | 27 +++++++++++++++++++ .../java/org/xmtp/android/library/Contacts.kt | 8 +++--- 2 files changed, 31 insertions(+), 4 deletions(-) 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 a5df80432..5000754e7 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt @@ -1,5 +1,6 @@ package org.xmtp.android.library +import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 import app.cash.turbine.test import com.google.protobuf.kotlin.toByteString @@ -859,4 +860,30 @@ class ConversationTest { assertFalse(Topic.isValidTopic(directMessageV2)) assertFalse(Topic.isValidTopic(preferenceList)) } + + @Test + fun testConsentWorksAcrossPagination() { + val privateKeyData = listOf(0x08, 0x36, 0x20, 0x0f, 0xfa, 0xfa, 0x17, 0xa3, 0xcb, 0x8b, 0x54, 0xf2, 0x2d, 0x6a, 0xfa, 0x60, 0xb1, 0x3d, 0xa4, 0x87, 0x26, 0x54, 0x32, 0x41, 0xad, 0xc5, 0xc2, 0x50, 0xdb, 0xb0, 0xe0, 0xcd) + .map { it.toByte() } + .toByteArray() + // Use hardcoded privateKey + val privateKey = PrivateKeyBuilder.buildFromPrivateKeyData(privateKeyData) + val privateKeyBuilder = PrivateKeyBuilder(privateKey) + val options = ClientOptions(api = ClientOptions.Api(XMTPEnvironment.DEV, isSecure = true)) + val randomClient = Client().create(account = privateKeyBuilder, options = options) + val conversations = randomClient.conversations.list() + val addresses = conversations.map { it.peerAddress } + + val firstHundred = addresses.take(100) + val lastHundred = addresses.takeLast(100) + + randomClient.contacts.allow(firstHundred) + randomClient.contacts.deny(lastHundred) + + randomClient.contacts.refreshConsentList() + + randomClient.contacts.consentList.entries.size + + assertEquals(200, randomClient.contacts.consentList.entries.size) + } } 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 28724fe55..a1c4f6c7a 100644 --- a/library/src/main/java/org/xmtp/android/library/Contacts.kt +++ b/library/src/main/java/org/xmtp/android/library/Contacts.kt @@ -1,5 +1,6 @@ package org.xmtp.android.library +import android.util.Log import kotlinx.coroutines.runBlocking import org.xmtp.android.library.messages.ContactBundle import org.xmtp.android.library.messages.ContactBundleBuilder @@ -52,14 +53,13 @@ class ConsentList(val client: Client) { @OptIn(ExperimentalUnsignedTypes::class) suspend fun load(): ConsentList { - val envelopes = client.query( - Topic.preferenceList(identifier), + val envelopes = client.apiClient.envelopes( + Topic.preferenceList(identifier).description, Pagination(direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING) ) val consentList = ConsentList(client) val preferences: MutableList = mutableListOf() - - for (envelope in envelopes.envelopesList) { + for (envelope in envelopes) { val payload = uniffi.xmtp_dh.userPreferencesDecrypt( publicKey.toByteArray().toUByteArray().toList(), privateKey.toByteArray().toUByteArray().toList(), From e0b758b74a86ee29961bf8da5473a9badfb199e4 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 3 Jan 2024 13:09:57 -0800 Subject: [PATCH 2/3] remove dev test --- .../xmtp/android/library/ConversationTest.kt | 26 ------------------- 1 file changed, 26 deletions(-) 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 5000754e7..21c823d69 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt @@ -860,30 +860,4 @@ class ConversationTest { assertFalse(Topic.isValidTopic(directMessageV2)) assertFalse(Topic.isValidTopic(preferenceList)) } - - @Test - fun testConsentWorksAcrossPagination() { - val privateKeyData = listOf(0x08, 0x36, 0x20, 0x0f, 0xfa, 0xfa, 0x17, 0xa3, 0xcb, 0x8b, 0x54, 0xf2, 0x2d, 0x6a, 0xfa, 0x60, 0xb1, 0x3d, 0xa4, 0x87, 0x26, 0x54, 0x32, 0x41, 0xad, 0xc5, 0xc2, 0x50, 0xdb, 0xb0, 0xe0, 0xcd) - .map { it.toByte() } - .toByteArray() - // Use hardcoded privateKey - val privateKey = PrivateKeyBuilder.buildFromPrivateKeyData(privateKeyData) - val privateKeyBuilder = PrivateKeyBuilder(privateKey) - val options = ClientOptions(api = ClientOptions.Api(XMTPEnvironment.DEV, isSecure = true)) - val randomClient = Client().create(account = privateKeyBuilder, options = options) - val conversations = randomClient.conversations.list() - val addresses = conversations.map { it.peerAddress } - - val firstHundred = addresses.take(100) - val lastHundred = addresses.takeLast(100) - - randomClient.contacts.allow(firstHundred) - randomClient.contacts.deny(lastHundred) - - randomClient.contacts.refreshConsentList() - - randomClient.contacts.consentList.entries.size - - assertEquals(200, randomClient.contacts.consentList.entries.size) - } } From fbde00202e3f401cff2e855032c9d2ce6d08f04f Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 3 Jan 2024 13:36:08 -0800 Subject: [PATCH 3/3] optimize imports --- .../java/org/xmtp/android/library/ConversationTest.kt | 1 - library/src/main/java/org/xmtp/android/library/Contacts.kt | 1 - 2 files changed, 2 deletions(-) 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 21c823d69..a5df80432 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt @@ -1,6 +1,5 @@ package org.xmtp.android.library -import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 import app.cash.turbine.test import com.google.protobuf.kotlin.toByteString 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 a1c4f6c7a..28584cedb 100644 --- a/library/src/main/java/org/xmtp/android/library/Contacts.kt +++ b/library/src/main/java/org/xmtp/android/library/Contacts.kt @@ -1,6 +1,5 @@ package org.xmtp.android.library -import android.util.Log import kotlinx.coroutines.runBlocking import org.xmtp.android.library.messages.ContactBundle import org.xmtp.android.library.messages.ContactBundleBuilder