Skip to content

Commit

Permalink
Fix order of loading consent (#128)
Browse files Browse the repository at this point in the history
* fix the allow block list overwritting in the wrong direction

* revert back to previous way of loading
  • Loading branch information
nplasterer authored Oct 26, 2023
1 parent 7e229a1 commit d42462b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@ class ConversationTest {
assertTrue(isAllowed)
assertTrue(bobClient.contacts.isAllowed(alice.walletAddress))

bobClient.contacts.block(listOf(alice.walletAddress))
bobClient.contacts.refreshConsentList()

val isBlocked = bobConversation.consentState() == ConsentState.BLOCKED
assertTrue(isBlocked)

val aliceConversation = aliceClient.conversations.list()[0]
val isUnknown = aliceConversation.consentState() == ConsentState.UNKNOWN

Expand Down
14 changes: 11 additions & 3 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class ConsentState {
BLOCKED,
UNKNOWN
}

data class ConsentListEntry(
val value: String,
val entryType: EntryType,
Expand Down Expand Up @@ -67,23 +68,30 @@ class ConsentList(val client: Client) {
)
}

preferences.iterator().forEach { preference ->
preferences.reversed().iterator().forEach { preference ->
preference.allow?.walletAddressesList?.forEach { address ->
consentList.allow(address)
}
preference.block?.walletAddressesList?.forEach { address ->
consentList.block(address)
}
}

return consentList
}

@OptIn(ExperimentalUnsignedTypes::class)
fun publish(entry: ConsentListEntry) {
val payload = PrivatePreferencesAction.newBuilder().also {
when (entry.consentType) {
ConsentState.ALLOWED -> it.setAllow(PrivatePreferencesAction.Allow.newBuilder().addWalletAddresses(entry.value))
ConsentState.BLOCKED -> it.setBlock(PrivatePreferencesAction.Block.newBuilder().addWalletAddresses(entry.value))
ConsentState.ALLOWED -> it.setAllow(
PrivatePreferencesAction.Allow.newBuilder().addWalletAddresses(entry.value)
)

ConsentState.BLOCKED -> it.setBlock(
PrivatePreferencesAction.Block.newBuilder().addWalletAddresses(entry.value)
)

ConsentState.UNKNOWN -> it.clearMessageType()
}
}.build()
Expand Down

0 comments on commit d42462b

Please sign in to comment.