Skip to content

Commit

Permalink
Add entry to the consent list entries (#148)
Browse files Browse the repository at this point in the history
* make the consent list return an entry

* add a return to refresh consent list so we can know when it's finished executing
  • Loading branch information
nplasterer authored Dec 7, 2023
1 parent f8e90d8 commit e5f6592
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class ConsentListEntry(
}

class ConsentList(val client: Client) {
val entries: MutableMap<String, ConsentState> = mutableMapOf()
val entries: MutableMap<String, ConsentListEntry> = mutableMapOf()
private val publicKey =
client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
private val privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes
Expand Down Expand Up @@ -117,21 +117,23 @@ class ConsentList(val client: Client) {
}

fun allow(address: String): ConsentListEntry {
entries[ConsentListEntry.address(address).key] = ConsentState.ALLOWED
val entry = ConsentListEntry.address(address, ConsentState.ALLOWED)
entries[ConsentListEntry.address(address).key] = entry

return ConsentListEntry.address(address, ConsentState.ALLOWED)
return entry
}

fun deny(address: String): ConsentListEntry {
entries[ConsentListEntry.address(address).key] = ConsentState.DENIED
val entry = ConsentListEntry.address(address, ConsentState.DENIED)
entries[ConsentListEntry.address(address).key] = entry

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

fun state(address: String): ConsentState {
val state = entries[ConsentListEntry.address(address).key]
val entry = entries[ConsentListEntry.address(address).key]

return state ?: ConsentState.UNKNOWN
return entry?.consentType ?: ConsentState.UNKNOWN
}
}

Expand All @@ -143,10 +145,11 @@ data class Contacts(

var consentList: ConsentList = ConsentList(client)

fun refreshConsentList() {
fun refreshConsentList(): ConsentList {
runBlocking {
consentList = ConsentList(client).load()
}
return consentList
}

fun isAllowed(address: String): Boolean {
Expand Down

0 comments on commit e5f6592

Please sign in to comment.