Skip to content

Commit

Permalink
rename and fix up the lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 7, 2024
1 parent ea00cc3 commit 1c61727
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
16 changes: 7 additions & 9 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.xmtp.android.library

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import app.cash.turbine.test
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -17,11 +16,10 @@ import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionAction
import org.xmtp.android.library.codecs.ReactionCodec
import org.xmtp.android.library.codecs.ReactionSchema
import org.xmtp.android.library.libxmtp.Message.*
import org.xmtp.android.library.libxmtp.Message.MessageDeliveryStatus
import org.xmtp.android.library.messages.PrivateKey
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
import java.security.SecureRandom

@RunWith(AndroidJUnit4::class)
class DmTest {
Expand Down Expand Up @@ -116,7 +114,7 @@ class DmTest {
dm.send("howdy")
dm.send("gm")
dm.sync()
assertEquals(boClient.preferences.consentList.groupState(dm.id), ConsentState.ALLOWED)
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.ALLOWED)
assertEquals(dm.consentState(), ConsentState.ALLOWED)
}
}
Expand Down Expand Up @@ -260,32 +258,32 @@ class DmTest {
runBlocking {
val dm =
boClient.conversations.findOrCreateDm(alix.walletAddress)
assertEquals(boClient.preferences.consentList.groupState(dm.id), ConsentState.ALLOWED)
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.ALLOWED)

assertEquals(dm.consentState(), ConsentState.ALLOWED)

boClient.preferences.consentList.setConsentState(
listOf(
ConsentListEntry(
dm.id,
EntryType.GROUP_ID,
EntryType.CONVERSATION_ID,
ConsentState.DENIED
)
)
)
assertEquals(boClient.preferences.consentList.groupState(dm.id), ConsentState.DENIED)
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.DENIED)
assertEquals(dm.consentState(), ConsentState.DENIED)

boClient.preferences.consentList.setConsentState(
listOf(
ConsentListEntry(
dm.id,
EntryType.GROUP_ID,
EntryType.CONVERSATION_ID,
ConsentState.ALLOWED
)
)
)
assertEquals(boClient.preferences.consentList.groupState(dm.id), ConsentState.ALLOWED)
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.ALLOWED)
assertEquals(dm.consentState(), ConsentState.ALLOWED)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionAction
import org.xmtp.android.library.codecs.ReactionCodec
import org.xmtp.android.library.codecs.ReactionSchema
import org.xmtp.android.library.libxmtp.Message.*
import org.xmtp.android.library.libxmtp.Message.MessageDeliveryStatus
import org.xmtp.android.library.messages.PrivateKey
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
Expand Down Expand Up @@ -111,11 +111,11 @@ class GroupTest {

runBlocking {
assertEquals(
boClient.preferences.consentList.groupState(boGroup.id),
boClient.preferences.consentList.conversationState(boGroup.id),
ConsentState.ALLOWED
)
assertEquals(
alixClient.preferences.consentList.groupState(alixGroup.id),
alixClient.preferences.consentList.conversationState(alixGroup.id),
ConsentState.UNKNOWN
)
}
Expand Down Expand Up @@ -419,7 +419,7 @@ class GroupTest {
group.sync()
assertEquals(group.consentState(), ConsentState.ALLOWED)
assertEquals(
boClient.preferences.consentList.groupState(group.id),
boClient.preferences.consentList.conversationState(group.id),
ConsentState.ALLOWED
)
}
Expand Down Expand Up @@ -694,7 +694,7 @@ class GroupTest {
)
)
assertEquals(
boClient.preferences.consentList.groupState(group.id),
boClient.preferences.consentList.conversationState(group.id),
ConsentState.ALLOWED
)
assertEquals(group.consentState(), ConsentState.ALLOWED)
Expand All @@ -703,17 +703,17 @@ class GroupTest {
listOf(
ConsentListEntry(
group.id,
EntryType.GROUP_ID,
EntryType.CONVERSATION_ID,
ConsentState.DENIED
)
)
)
assertEquals(boClient.preferences.consentList.groupState(group.id), ConsentState.DENIED)
assertEquals(boClient.preferences.consentList.conversationState(group.id), ConsentState.DENIED)
assertEquals(group.consentState(), ConsentState.DENIED)

group.updateConsentState(ConsentState.ALLOWED)
assertEquals(
boClient.preferences.consentList.groupState(group.id),
boClient.preferences.consentList.conversationState(group.id),
ConsentState.ALLOWED
)
assertEquals(group.consentState(), ConsentState.ALLOWED)
Expand Down Expand Up @@ -762,7 +762,6 @@ class GroupTest {
ConsentState.DENIED
)


boClient.preferences.consentList.setConsentState(
listOf(
ConsentListEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ class SmartContractWalletTest {
runBlocking { boGroup.sync() }
assertEquals(boGroup.messages().first().body, "gm")
assertEquals(boGroup.messages().first().id, messageId)
assertEquals(boGroup.messages().first().deliveryStatus, Message.MessageDeliveryStatus.PUBLISHED)
assertEquals(
boGroup.messages().first().deliveryStatus,
Message.MessageDeliveryStatus.PUBLISHED
)
assertEquals(boGroup.messages().size, 3)

runBlocking { davonSCWClient.conversations.syncConversations() }
Expand Down Expand Up @@ -159,7 +162,7 @@ class SmartContractWalletTest {
)
}
assertEquals(
davonSCWClient.preferences.consentList.groupState(davonGroup.id),
davonSCWClient.preferences.consentList.conversationState(davonGroup.id),
ConsentState.ALLOWED
)
assertEquals(davonGroup.consentState(), ConsentState.ALLOWED)
Expand All @@ -168,17 +171,20 @@ class SmartContractWalletTest {
listOf(
ConsentListEntry(
davonGroup.id,
EntryType.GROUP_ID,
EntryType.CONVERSATION_ID,
ConsentState.DENIED
)
)
)
assertEquals(davonSCWClient.preferences.consentList.groupState(davonGroup.id), ConsentState.DENIED)
assertEquals(
davonSCWClient.preferences.consentList.conversationState(davonGroup.id),
ConsentState.DENIED
)
assertEquals(davonGroup.consentState(), ConsentState.DENIED)

davonGroup.updateConsentState(ConsentState.ALLOWED)
assertEquals(
davonSCWClient.preferences.consentList.groupState(davonGroup.id),
davonSCWClient.preferences.consentList.conversationState(davonGroup.id),
ConsentState.ALLOWED
)
assertEquals(davonGroup.consentState(), ConsentState.ALLOWED)
Expand Down Expand Up @@ -234,7 +240,6 @@ class SmartContractWalletTest {
ConsentState.DENIED
)


davonSCWClient.preferences.consentList.setConsentState(
listOf(
ConsentListEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,4 @@ data class Conversations(
val stream = ffiConversations.streamAllMessages(messageCallback)
awaitClose { stream.end() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ enum class ConsentState {
return when (option) {
ALLOWED -> FfiConsentState.ALLOWED
DENIED -> FfiConsentState.DENIED
else -> FfiConsentState.UNKNOWN
UNKNOWN -> FfiConsentState.UNKNOWN
}
}

fun fromFfiConsentState(option: FfiConsentState): ConsentState {
return when (option) {
FfiConsentState.ALLOWED -> ALLOWED
FfiConsentState.DENIED -> DENIED
else -> UNKNOWN
FfiConsentState.UNKNOWN -> UNKNOWN
}
}
}
}

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

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

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

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

fun inboxId(
Expand All @@ -87,7 +87,7 @@ data class ConsentListEntry(

class ConsentList(
val client: Client,
private val ffiClient: FfiXmtpClient
private val ffiClient: FfiXmtpClient,
) {
suspend fun setConsentState(entries: List<ConsentListEntry>) {
ffiClient.setConsentStates(entries.map { it.toFfiConsent() })
Expand All @@ -110,7 +110,7 @@ class ConsentList(
)
}

suspend fun groupState(groupId: String): ConsentState {
suspend fun conversationState(groupId: String): ConsentState {
return ConsentState.fromFfiConsentState(
ffiClient.getConsentState(
FfiConsentEntityType.CONVERSATION_ID,
Expand Down

0 comments on commit 1c61727

Please sign in to comment.