Skip to content

Commit d42462b

Browse files
authored
Fix order of loading consent (#128)
* fix the allow block list overwritting in the wrong direction * revert back to previous way of loading
1 parent 7e229a1 commit d42462b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt

+6
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ class ConversationTest {
723723
assertTrue(isAllowed)
724724
assertTrue(bobClient.contacts.isAllowed(alice.walletAddress))
725725

726+
bobClient.contacts.block(listOf(alice.walletAddress))
727+
bobClient.contacts.refreshConsentList()
728+
729+
val isBlocked = bobConversation.consentState() == ConsentState.BLOCKED
730+
assertTrue(isBlocked)
731+
726732
val aliceConversation = aliceClient.conversations.list()[0]
727733
val isUnknown = aliceConversation.consentState() == ConsentState.UNKNOWN
728734

library/src/main/java/org/xmtp/android/library/Contacts.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum class ConsentState {
1414
BLOCKED,
1515
UNKNOWN
1616
}
17+
1718
data class ConsentListEntry(
1819
val value: String,
1920
val entryType: EntryType,
@@ -67,23 +68,30 @@ class ConsentList(val client: Client) {
6768
)
6869
}
6970

70-
preferences.iterator().forEach { preference ->
71+
preferences.reversed().iterator().forEach { preference ->
7172
preference.allow?.walletAddressesList?.forEach { address ->
7273
consentList.allow(address)
7374
}
7475
preference.block?.walletAddressesList?.forEach { address ->
7576
consentList.block(address)
7677
}
7778
}
79+
7880
return consentList
7981
}
8082

8183
@OptIn(ExperimentalUnsignedTypes::class)
8284
fun publish(entry: ConsentListEntry) {
8385
val payload = PrivatePreferencesAction.newBuilder().also {
8486
when (entry.consentType) {
85-
ConsentState.ALLOWED -> it.setAllow(PrivatePreferencesAction.Allow.newBuilder().addWalletAddresses(entry.value))
86-
ConsentState.BLOCKED -> it.setBlock(PrivatePreferencesAction.Block.newBuilder().addWalletAddresses(entry.value))
87+
ConsentState.ALLOWED -> it.setAllow(
88+
PrivatePreferencesAction.Allow.newBuilder().addWalletAddresses(entry.value)
89+
)
90+
91+
ConsentState.BLOCKED -> it.setBlock(
92+
PrivatePreferencesAction.Block.newBuilder().addWalletAddresses(entry.value)
93+
)
94+
8795
ConsentState.UNKNOWN -> it.clearMessageType()
8896
}
8997
}.build()

0 commit comments

Comments
 (0)