Skip to content

Commit

Permalink
rename all consent group to conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 24, 2024
1 parent 3e9a9da commit 1be05fe
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 58 deletions.
12 changes: 6 additions & 6 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class DmTest {
dm.send("howdy")
dm.send("gm")
dm.sync()
assert(boClient.contacts.isGroupAllowed(dm.id))
assertEquals(boClient.contacts.consentList.groupState(dm.id), ConsentState.ALLOWED)
assert(boClient.contacts.isConversationAllowed(dm.id))
assertEquals(boClient.contacts.consentList.conversationState(dm.id), ConsentState.ALLOWED)
assertEquals(dm.consentState(), ConsentState.ALLOWED)
}
}
Expand Down Expand Up @@ -344,15 +344,15 @@ class DmTest {
runBlocking {
val dm =
boClient.conversations.findOrCreateDm(alix.walletAddress)
assert(boClient.contacts.isGroupAllowed(dm.id))
assert(boClient.contacts.isConversationAllowed(dm.id))
assertEquals(dm.consentState(), ConsentState.ALLOWED)

boClient.contacts.denyGroups(listOf(dm.id))
assert(boClient.contacts.isGroupDenied(dm.id))
boClient.contacts.denyConversations(listOf(dm.id))
assert(boClient.contacts.isConversationDenied(dm.id))
assertEquals(dm.consentState(), ConsentState.DENIED)

dm.updateConsentState(ConsentState.ALLOWED)
assert(boClient.contacts.isGroupAllowed(dm.id))
assert(boClient.contacts.isConversationAllowed(dm.id))
assertEquals(dm.consentState(), ConsentState.ALLOWED)
}
}
Expand Down
20 changes: 10 additions & 10 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ class GroupTest {
assert(alixGroup.id.isNotEmpty())

runBlocking {
assertEquals(boClient.contacts.consentList.groupState(boGroup.id), ConsentState.ALLOWED)
assertEquals(boClient.contacts.consentList.conversationState(boGroup.id), ConsentState.ALLOWED)
assertEquals(
alixClient.contacts.consentList.groupState(alixGroup.id),
alixClient.contacts.consentList.conversationState(alixGroup.id),
ConsentState.UNKNOWN
)
}
Expand Down Expand Up @@ -446,8 +446,8 @@ class GroupTest {
group.send("howdy")
group.send("gm")
group.sync()
assert(boClient.contacts.isGroupAllowed(group.id))
assertEquals(boClient.contacts.consentList.groupState(group.id), ConsentState.ALLOWED)
assert(boClient.contacts.isConversationAllowed(group.id))
assertEquals(boClient.contacts.consentList.conversationState(group.id), ConsentState.ALLOWED)
}
}

Expand Down Expand Up @@ -813,15 +813,15 @@ class GroupTest {
caro.walletAddress
)
)
assert(boClient.contacts.isGroupAllowed(group.id))
assert(boClient.contacts.isConversationAllowed(group.id))
assertEquals(group.consentState(), ConsentState.ALLOWED)

boClient.contacts.denyGroups(listOf(group.id))
assert(boClient.contacts.isGroupDenied(group.id))
boClient.contacts.denyConversations(listOf(group.id))
assert(boClient.contacts.isConversationDenied(group.id))
assertEquals(group.consentState(), ConsentState.DENIED)

group.updateConsentState(ConsentState.ALLOWED)
assert(boClient.contacts.isGroupAllowed(group.id))
assert(boClient.contacts.isConversationAllowed(group.id))
assertEquals(group.consentState(), ConsentState.ALLOWED)
}
}
Expand Down Expand Up @@ -904,9 +904,9 @@ class GroupTest {
}
runBlocking { alixClient.conversations.syncGroups() }
val alixGroup: Group = alixClient.findGroup(boGroup.id)!!
runBlocking { assert(!alixClient.contacts.isGroupAllowed(boGroup.id)) }
runBlocking { assert(!alixClient.contacts.isConversationAllowed(boGroup.id)) }
val preparedMessageId = runBlocking { alixGroup.prepareMessage("Test text") }
runBlocking { assert(alixClient.contacts.isGroupAllowed(boGroup.id)) }
runBlocking { assert(alixClient.contacts.isConversationAllowed(boGroup.id)) }
assertEquals(alixGroup.messages().size, 1)
assertEquals(alixGroup.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 0)
assertEquals(alixGroup.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ class SmartContractWalletTest {
)
)
}
assert(davonSCWClient.contacts.isGroupAllowed(davonGroup.id))
assert(davonSCWClient.contacts.isConversationAllowed(davonGroup.id))
assertEquals(davonGroup.consentState(), ConsentState.ALLOWED)

davonSCWClient.contacts.denyGroups(listOf(davonGroup.id))
assert(davonSCWClient.contacts.isGroupDenied(davonGroup.id))
davonSCWClient.contacts.denyConversations(listOf(davonGroup.id))
assert(davonSCWClient.contacts.isConversationDenied(davonGroup.id))
assertEquals(davonGroup.consentState(), ConsentState.DENIED)

davonGroup.updateConsentState(ConsentState.ALLOWED)
assert(davonSCWClient.contacts.isGroupAllowed(davonGroup.id))
assert(davonSCWClient.contacts.isConversationAllowed(davonGroup.id))
assertEquals(davonGroup.consentState(), ConsentState.ALLOWED)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ class V3ClientTest {
fun testGroupConsent() {
runBlocking {
val group = boV3Client.conversations.newGroup(listOf(caroV2V3.walletAddress))
assert(boV3Client.contacts.isGroupAllowed(group.id))
assert(boV3Client.contacts.isConversationAllowed(group.id))
assertEquals(group.consentState(), ConsentState.ALLOWED)

boV3Client.contacts.denyGroups(listOf(group.id))
assert(boV3Client.contacts.isGroupDenied(group.id))
boV3Client.contacts.denyConversations(listOf(group.id))
assert(boV3Client.contacts.isConversationDenied(group.id))
assertEquals(group.consentState(), ConsentState.DENIED)

group.updateConsentState(ConsentState.ALLOWED)
assert(boV3Client.contacts.isGroupAllowed(group.id))
assert(boV3Client.contacts.isConversationAllowed(group.id))
assertEquals(group.consentState(), ConsentState.ALLOWED)
}
}
Expand Down
52 changes: 26 additions & 26 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ enum class ConsentState {

enum class EntryType {
ADDRESS,
GROUP_ID,
CONVERSATION_ID,
INBOX_ID;

companion object {
fun toFfiConsentEntityType(option: EntryType): FfiConsentEntityType {
return when (option) {
EntryType.ADDRESS -> FfiConsentEntityType.ADDRESS
EntryType.GROUP_ID -> FfiConsentEntityType.CONVERSATION_ID
EntryType.CONVERSATION_ID -> FfiConsentEntityType.CONVERSATION_ID
EntryType.INBOX_ID -> FfiConsentEntityType.INBOX_ID
}
}

fun fromFfiConsentEntityType(option: FfiConsentEntityType): EntryType {
return when (option) {
FfiConsentEntityType.ADDRESS -> EntryType.ADDRESS
FfiConsentEntityType.CONVERSATION_ID -> EntryType.GROUP_ID
FfiConsentEntityType.CONVERSATION_ID -> EntryType.CONVERSATION_ID
FfiConsentEntityType.INBOX_ID -> EntryType.INBOX_ID
}
}
Expand All @@ -75,11 +75,11 @@ data class ConsentListEntry(
return ConsentListEntry(address, EntryType.ADDRESS, type)
}

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

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

preference.allowInboxId?.inboxIdsList?.forEach { inboxId ->
Expand Down Expand Up @@ -189,12 +189,12 @@ class ConsentList(
.addWalletAddresses(entry.value)
)

EntryType.GROUP_ID to ConsentState.ALLOWED -> it.setAllowGroup(
EntryType.CONVERSATION_ID to ConsentState.ALLOWED -> it.setAllowGroup(
PrivatePreferencesAction.AllowGroup.newBuilder()
.addGroupIds(entry.value)
)

EntryType.GROUP_ID to ConsentState.DENIED -> it.setDenyGroup(
EntryType.CONVERSATION_ID to ConsentState.DENIED -> it.setDenyGroup(
PrivatePreferencesAction.DenyGroup.newBuilder().addGroupIds(entry.value)
)

Expand Down Expand Up @@ -256,15 +256,15 @@ class ConsentList(
return entry
}

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

return entry
}

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

return entry
Expand Down Expand Up @@ -297,7 +297,7 @@ class ConsentList(
return entry?.consentType ?: ConsentState.UNKNOWN
}

suspend fun groupState(groupId: String): ConsentState {
suspend fun conversationState(groupId: String): ConsentState {
client.v3Client?.let {
return ConsentState.fromFfiConsentState(
it.getConsentState(
Expand All @@ -306,7 +306,7 @@ class ConsentList(
)
)
}
val entry = entries[ConsentListEntry.groupId(groupId).key]
val entry = entries[ConsentListEntry.conversationId(groupId).key]
return entry?.consentType ?: ConsentState.UNKNOWN
}

Expand Down Expand Up @@ -351,16 +351,16 @@ data class Contacts(
consentList.publish(entries)
}

suspend fun allowGroups(groupIds: List<String>) {
val entries = groupIds.map {
consentList.allowGroup(it)
suspend fun allowConversations(conversationIds: List<String>) {
val entries = conversationIds.map {
consentList.allowConversation(it)
}
consentList.publish(entries)
}

suspend fun denyGroups(groupIds: List<String>) {
val entries = groupIds.map {
consentList.denyGroup(it)
suspend fun denyConversations(conversationIds: List<String>) {
val entries = conversationIds.map {
consentList.denyConversation(it)
}
consentList.publish(entries)
}
Expand All @@ -387,12 +387,12 @@ data class Contacts(
return consentList.state(address) == ConsentState.DENIED
}

suspend fun isGroupAllowed(groupId: String): Boolean {
return consentList.groupState(groupId) == ConsentState.ALLOWED
suspend fun isConversationAllowed(conversationId: String): Boolean {
return consentList.conversationState(conversationId) == ConsentState.ALLOWED
}

suspend fun isGroupDenied(groupId: String): Boolean {
return consentList.groupState(groupId) == ConsentState.DENIED
suspend fun isConversationDenied(conversationId: String): Boolean {
return consentList.conversationState(conversationId) == ConsentState.DENIED
}

suspend fun isInboxAllowed(inboxId: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ data class Conversations(
suspend fun conversationFromWelcome(envelopeBytes: ByteArray): Conversation {
val conversation = libXMTPConversations?.processStreamedWelcomeMessage(envelopeBytes)
?: throw XMTPException("Client does not support Groups")
if (conversation.groupMetadata().conversationType() == "dm") {
return Conversation.Dm(Dm(client, conversation))
return if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(client, conversation))
} else {
return Conversation.Group(Group(client, conversation))
Conversation.Group(Group(client, conversation))
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ data class Conversations(
customPermissionPolicySet = permissionsPolicySet
)
) ?: throw XMTPException("Client does not support Groups")
client.contacts.allowGroups(groupIds = listOf(group.id().toHex()))
client.contacts.allowConversations(groupIds = listOf(group.id().toHex()))

return Group(client, group)
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/org/xmtp/android/library/Dm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ class Dm(val client: Client, private val libXMTPGroup: FfiConversation) {
suspend fun updateConsentState(state: ConsentState) {
if (client.hasV2Client) {
when (state) {
ConsentState.ALLOWED -> client.contacts.allowGroups(groupIds = listOf(id))
ConsentState.DENIED -> client.contacts.denyGroups(groupIds = listOf(id))
ConsentState.ALLOWED -> client.contacts.allowConversations(groupIds = listOf(id))
ConsentState.DENIED -> client.contacts.denyConversations(groupIds = listOf(id))
ConsentState.UNKNOWN -> Unit
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class Group(val client: Client, private val libXMTPGroup: FfiConversation) {
suspend fun updateConsentState(state: ConsentState) {
if (client.hasV2Client) {
when (state) {
ConsentState.ALLOWED -> client.contacts.allowGroups(groupIds = listOf(id))
ConsentState.DENIED -> client.contacts.denyGroups(groupIds = listOf(id))
ConsentState.ALLOWED -> client.contacts.allowConversations(groupIds = listOf(id))
ConsentState.DENIED -> client.contacts.denyConversations(groupIds = listOf(id))
ConsentState.UNKNOWN -> Unit
}
}
Expand Down

0 comments on commit 1be05fe

Please sign in to comment.