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 f0cc338d9..01e92af38 100644 --- a/library/src/main/java/org/xmtp/android/library/Contacts.kt +++ b/library/src/main/java/org/xmtp/android/library/Contacts.kt @@ -14,6 +14,7 @@ enum class ConsentState { BLOCKED, UNKNOWN } + data class ConsentListEntry( val value: String, val entryType: EntryType, @@ -68,18 +69,11 @@ class ConsentList(val client: Client) { } preferences.reversed().iterator().forEach { preference -> - when(preference.messageTypeCase) { - PrivatePreferencesAction.MessageTypeCase.ALLOW -> { - preference.allow.walletAddressesList.forEach { - consentList.allow(it) - } - } - PrivatePreferencesAction.MessageTypeCase.BLOCK -> { - preference.block.walletAddressesList.forEach { - consentList.block(it) - } - } - else -> Unit + preference.allow?.walletAddressesList?.forEach { address -> + consentList.allow(address) + } + preference.block?.walletAddressesList?.forEach { address -> + consentList.block(address) } } @@ -90,8 +84,14 @@ class ConsentList(val client: Client) { 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()