Skip to content

Commit

Permalink
Make the group consent a string (#266)
Browse files Browse the repository at this point in the history
* make the tweeks in android

* one more place

* fix up the linter
  • Loading branch information
nplasterer authored Jul 1, 2024
1 parent 9ee782f commit cf50a1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ dependencies {
implementation 'org.web3j:crypto:5.0.0'
implementation "net.java.dev.jna:jna:5.14.0@aar"
api 'com.google.protobuf:protobuf-kotlin-lite:3.22.3'
api 'org.xmtp:proto-kotlin:3.61.1'
api 'org.xmtp:proto-kotlin:3.62.1'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'app.cash.turbine:turbine:1.1.0'
Expand Down
23 changes: 11 additions & 12 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.xmtp.android.library

import com.google.protobuf.kotlin.toByteString
import kotlinx.coroutines.runBlocking
import org.xmtp.android.library.messages.ContactBundle
import org.xmtp.android.library.messages.ContactBundleBuilder
Expand Down Expand Up @@ -38,10 +37,10 @@ data class ConsentListEntry(
}

fun groupId(
groupId: ByteArray,
groupId: String,
type: ConsentState = ConsentState.UNKNOWN,
): ConsentListEntry {
return ConsentListEntry(groupId.toHex(), EntryType.GROUP_ID, type)
return ConsentListEntry(groupId, EntryType.GROUP_ID, type)
}

fun inboxId(
Expand Down Expand Up @@ -108,10 +107,10 @@ class ConsentList(
deny(address)
}
preference.allowGroup?.groupIdsList?.forEach { groupId ->
allowGroup(groupId.toByteArray())
allowGroup(groupId)
}
preference.denyGroup?.groupIdsList?.forEach { groupId ->
denyGroup(groupId.toByteArray())
denyGroup(groupId)
}

preference.allowInboxId?.inboxIdsList?.forEach { inboxId ->
Expand Down Expand Up @@ -152,13 +151,13 @@ class ConsentList(
ConsentState.ALLOWED ->
it.setAllowGroup(
PrivatePreferencesAction.AllowGroup.newBuilder()
.addGroupIds(entry.value.hexToByteArray().toByteString()),
.addGroupIds(entry.value),
)

ConsentState.DENIED ->
it.setDenyGroup(
PrivatePreferencesAction.DenyGroup.newBuilder()
.addGroupIds(entry.value.hexToByteArray().toByteString()),
.addGroupIds(entry.value),
)

ConsentState.UNKNOWN -> it.clearMessageType()
Expand Down Expand Up @@ -216,14 +215,14 @@ class ConsentList(
return entry
}

fun allowGroup(groupId: ByteArray): ConsentListEntry {
fun allowGroup(groupId: String): ConsentListEntry {
val entry = ConsentListEntry.groupId(groupId, ConsentState.ALLOWED)
entries[entry.key] = entry

return entry
}

fun denyGroup(groupId: ByteArray): ConsentListEntry {
fun denyGroup(groupId: String): ConsentListEntry {
val entry = ConsentListEntry.groupId(groupId, ConsentState.DENIED)
entries[entry.key] = entry

Expand Down Expand Up @@ -251,7 +250,7 @@ class ConsentList(
}

fun groupState(groupId: ByteArray): ConsentState {
val entry = entries[ConsentListEntry.groupId(groupId).key]
val entry = entries[ConsentListEntry.groupId(groupId.toHex()).key]

return entry?.consentType ?: ConsentState.UNKNOWN
}
Expand Down Expand Up @@ -291,14 +290,14 @@ data class Contacts(

suspend fun allowGroups(groupIds: List<ByteArray>) {
val entries = groupIds.map {
consentList.allowGroup(it)
consentList.allowGroup(it.toHex())
}
consentList.publish(entries)
}

suspend fun denyGroups(groupIds: List<ByteArray>) {
val entries = groupIds.map {
consentList.denyGroup(it)
consentList.denyGroup(it.toHex())
}
consentList.publish(entries)
}
Expand Down

0 comments on commit cf50a1f

Please sign in to comment.