Skip to content

Commit

Permalink
change block to deny
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 1, 2023
1 parent d42462b commit dfe48c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class ContactsTest {

assert(!result)

contacts.block(listOf(fixtures.alice.walletAddress))
contacts.deny(listOf(fixtures.alice.walletAddress))

result = contacts.isBlocked(fixtures.alice.walletAddress)
result = contacts.isDenied(fixtures.alice.walletAddress)
assert(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ class ConversationTest {
assertTrue(isAllowed)
assertTrue(bobClient.contacts.isAllowed(alice.walletAddress))

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

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

val aliceConversation = aliceClient.conversations.list()[0]
val isUnknown = aliceConversation.consentState() == ConsentState.UNKNOWN
Expand Down
20 changes: 10 additions & 10 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.Date

enum class ConsentState {
ALLOWED,
BLOCKED,
DENIED,
UNKNOWN
}

Expand Down Expand Up @@ -73,7 +73,7 @@ class ConsentList(val client: Client) {
consentList.allow(address)
}
preference.block?.walletAddressesList?.forEach { address ->
consentList.block(address)
consentList.deny(address)
}
}

Expand All @@ -88,7 +88,7 @@ class ConsentList(val client: Client) {
PrivatePreferencesAction.Allow.newBuilder().addWalletAddresses(entry.value)
)

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

Expand Down Expand Up @@ -117,10 +117,10 @@ class ConsentList(val client: Client) {
return ConsentListEntry.address(address, ConsentState.ALLOWED)
}

fun block(address: String): ConsentListEntry {
entries[ConsentListEntry.address(address).key] = ConsentState.BLOCKED
fun deny(address: String): ConsentListEntry {
entries[ConsentListEntry.address(address).key] = ConsentState.DENIED

return ConsentListEntry.address(address, ConsentState.BLOCKED)
return ConsentListEntry.address(address, ConsentState.DENIED)
}

fun state(address: String): ConsentState {
Expand Down Expand Up @@ -148,8 +148,8 @@ data class Contacts(
return consentList.state(address) == ConsentState.ALLOWED
}

fun isBlocked(address: String): Boolean {
return consentList.state(address) == ConsentState.BLOCKED
fun isDenied(address: String): Boolean {
return consentList.state(address) == ConsentState.DENIED
}

fun allow(addresses: List<String>) {
Expand All @@ -158,9 +158,9 @@ data class Contacts(
}
}

fun block(addresses: List<String>) {
fun deny(addresses: List<String>) {
for (address in addresses) {
ConsentList(client).publish(consentList.block(address))
ConsentList(client).publish(consentList.deny(address))
}
}

Expand Down

0 comments on commit dfe48c8

Please sign in to comment.