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 d6d3e455d..8490aa07f 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt @@ -718,20 +718,20 @@ class ConversationTest { @Test fun testCanHaveAllowState() { val bobConversation = bobClient.conversations.newConversation(alice.walletAddress, null) - val isAllowed = bobConversation.allowState() == PrivatePreferences.PrivatePreferencesAction.MessageTypeCase.ALLOW + val isAllowed = bobConversation.allowState() == AllowState.ALLOW // Conversations you start should start as allowed assertTrue(isAllowed) val aliceConversation = aliceClient.conversations.list()[0] - val isUnknown = aliceConversation.allowState() == PrivatePreferences.PrivatePreferencesAction.MessageTypeCase.MESSAGETYPE_NOT_SET + val isUnknown = aliceConversation.allowState() == AllowState.UNKNOWN // Conversations started with you should start as unknown assertTrue(isUnknown) aliceClient.contacts.allow(listOf(bob.walletAddress)) - val isBobAllowed = aliceConversation.allowState() == PrivatePreferences.PrivatePreferencesAction.MessageTypeCase.ALLOW + val isBobAllowed = aliceConversation.allowState() == AllowState.ALLOW assertTrue(isBobAllowed) val aliceClient2 = Client().create(aliceWallet, fakeApiClient) @@ -740,7 +740,7 @@ class ConversationTest { aliceClient2.contacts.refreshAllowList() // Allow state should sync across clients - val isBobAllowed2 = aliceConversation2.allowState() == PrivatePreferences.PrivatePreferencesAction.MessageTypeCase.ALLOW + val isBobAllowed2 = aliceConversation2.allowState() == AllowState.ALLOW assertTrue(isBobAllowed2) } 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 8b4350f13..8bb75e923 100644 --- a/library/src/main/java/org/xmtp/android/library/Contacts.kt +++ b/library/src/main/java/org/xmtp/android/library/Contacts.kt @@ -11,10 +11,15 @@ import java.util.Date typealias MessageType = PrivatePreferencesAction.MessageTypeCase +enum class AllowState { + ALLOW, + BLOCK, + UNKNOWN +} data class AllowListEntry( val value: String, val entryType: EntryType, - val permissionType: MessageType, + val permissionType: AllowState, ) { enum class EntryType { ADDRESS @@ -23,7 +28,7 @@ data class AllowListEntry( companion object { fun address( address: String, - type: MessageType = MessageType.MESSAGETYPE_NOT_SET, + type: AllowState = AllowState.UNKNOWN, ): AllowListEntry { return AllowListEntry(address, EntryType.ADDRESS, type) } @@ -34,7 +39,7 @@ data class AllowListEntry( } class AllowList(val client: Client) { - private val entries: MutableMap = mutableMapOf() + private val entries: MutableMap = mutableMapOf() private val publicKey = client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes private val privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes @@ -79,15 +84,9 @@ class AllowList(val client: Client) { fun publish(entry: AllowListEntry) { val payload = PrivatePreferencesAction.newBuilder().also { when (entry.permissionType) { - PrivatePreferencesAction.MessageTypeCase.ALLOW -> it.setAllow( - PrivatePreferencesAction.Allow.newBuilder().addWalletAddresses(entry.value) - ) - - PrivatePreferencesAction.MessageTypeCase.BLOCK -> it.setBlock( - PrivatePreferencesAction.Block.newBuilder().addWalletAddresses(entry.value) - ) - - PrivatePreferencesAction.MessageTypeCase.MESSAGETYPE_NOT_SET -> it.clearMessageType() + AllowState.ALLOW -> it.setAllow(PrivatePreferencesAction.Allow.newBuilder().addWalletAddresses(entry.value)) + AllowState.BLOCK -> it.setBlock(PrivatePreferencesAction.Block.newBuilder().addWalletAddresses(entry.value)) + AllowState.UNKNOWN -> it.clearMessageType() } }.build() @@ -107,21 +106,21 @@ class AllowList(val client: Client) { } fun allow(address: String): AllowListEntry { - entries[AllowListEntry.address(address).key] = MessageType.ALLOW + entries[AllowListEntry.address(address).key] = AllowState.ALLOW - return AllowListEntry.address(address, MessageType.ALLOW) + return AllowListEntry.address(address, AllowState.ALLOW) } fun block(address: String): AllowListEntry { - entries[AllowListEntry.address(address).key] = MessageType.BLOCK + entries[AllowListEntry.address(address).key] = AllowState.BLOCK - return AllowListEntry.address(address, MessageType.BLOCK) + return AllowListEntry.address(address, AllowState.BLOCK) } - fun state(address: String): MessageType { + fun state(address: String): AllowState { val state = entries[AllowListEntry.address(address).key] - return state ?: MessageType.MESSAGETYPE_NOT_SET + return state ?: AllowState.UNKNOWN } } @@ -140,11 +139,11 @@ data class Contacts( } fun isAllowed(address: String): Boolean { - return allowList.state(address) == MessageType.ALLOW + return allowList.state(address) == AllowState.ALLOW } fun isBlocked(address: String): Boolean { - return allowList.state(address) == MessageType.BLOCK + return allowList.state(address) == AllowState.BLOCK } fun allow(addresses: List) { diff --git a/library/src/main/java/org/xmtp/android/library/Conversation.kt b/library/src/main/java/org/xmtp/android/library/Conversation.kt index c6a55335d..9da904e1c 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversation.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversation.kt @@ -61,7 +61,7 @@ sealed class Conversation { } } - fun allowState(): MessageType { + fun allowState(): AllowState { val client: Client = when (this) { is V1 -> conversationV1.client is V2 -> conversationV2.client