Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Consent record name #338

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class ConversationsTest {
assertEquals(ConsentState.DENIED, dm2.consentState())
alixClient2.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
dm2.id,
EntryType.CONVERSATION_ID,
ConsentState.ALLOWED
Expand Down Expand Up @@ -272,7 +272,7 @@ class ConversationsTest {
alixClient2.conversations.syncAllConversations()
}
val alix2Group = alixClient2.findGroup(alixGroup.id)!!
val consent = mutableListOf<ConsentListEntry>()
val consent = mutableListOf<ConsentRecord>()
val job = CoroutineScope(Dispatchers.IO).launch {
try {
alixClient.preferences.streamConsent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class DmTest {

boClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
dm.id,
EntryType.CONVERSATION_ID,
ConsentState.DENIED
Expand All @@ -353,7 +353,7 @@ class DmTest {

boClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
dm.id,
EntryType.CONVERSATION_ID,
ConsentState.ALLOWED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ class GroupTest {

boClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
group.id,
EntryType.CONVERSATION_ID,
ConsentState.DENIED
Expand Down Expand Up @@ -770,7 +770,7 @@ class GroupTest {
)
boClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
alixClient.inboxId,
EntryType.INBOX_ID,
ConsentState.ALLOWED
Expand All @@ -787,7 +787,7 @@ class GroupTest {

boClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
alixClient.inboxId,
EntryType.INBOX_ID,
ConsentState.DENIED
Expand All @@ -804,7 +804,7 @@ class GroupTest {

boClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
alixClient.address,
EntryType.ADDRESS,
ConsentState.ALLOWED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class SmartContractWalletTest {

davonSCWClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
davonGroup.id,
EntryType.CONVERSATION_ID,
ConsentState.DENIED
Expand Down Expand Up @@ -258,7 +258,7 @@ class SmartContractWalletTest {
)
davonSCWClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
boEOAClient.inboxId,
EntryType.INBOX_ID,
ConsentState.ALLOWED
Expand All @@ -275,7 +275,7 @@ class SmartContractWalletTest {

davonSCWClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
boEOAClient.inboxId,
EntryType.INBOX_ID,
ConsentState.DENIED
Expand All @@ -292,7 +292,7 @@ class SmartContractWalletTest {

davonSCWClient.preferences.setConsentState(
listOf(
ConsentListEntry(
ConsentRecord(
eriSCWClient.address,
EntryType.ADDRESS,
ConsentState.ALLOWED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ enum class EntryType {
}
}

data class ConsentListEntry(
data class ConsentRecord(
val value: String,
val entryType: EntryType,
val consentType: ConsentState,
Expand All @@ -69,22 +69,22 @@ data class ConsentListEntry(
fun address(
address: String,
type: ConsentState = ConsentState.UNKNOWN,
): ConsentListEntry {
return ConsentListEntry(address, EntryType.ADDRESS, type)
): ConsentRecord {
return ConsentRecord(address, EntryType.ADDRESS, type)
}

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

fun inboxId(
inboxId: String,
type: ConsentState = ConsentState.UNKNOWN,
): ConsentListEntry {
return ConsentListEntry(inboxId, EntryType.INBOX_ID, type)
): ConsentRecord {
return ConsentRecord(inboxId, EntryType.INBOX_ID, type)
}
}

Expand All @@ -100,7 +100,7 @@ data class PrivatePreferences(
ffiClient.sendSyncRequest(FfiDeviceSyncKind.CONSENT)
}

suspend fun streamConsent(): Flow<ConsentListEntry> = callbackFlow {
suspend fun streamConsent(): Flow<ConsentRecord> = callbackFlow {
val consentCallback = object : FfiConsentCallback {
override fun onConsentUpdate(consent: List<FfiConsent>) {
consent.iterator().forEach {
Expand All @@ -118,20 +118,20 @@ data class PrivatePreferences(
awaitClose { stream.end() }
}

suspend fun setConsentState(entries: List<ConsentListEntry>) {
suspend fun setConsentState(entries: List<ConsentRecord>) {
ffiClient.setConsentStates(entries.map { it.toFfiConsent() })
}

private fun ConsentListEntry.toFfiConsent(): FfiConsent {
private fun ConsentRecord.toFfiConsent(): FfiConsent {
return FfiConsent(
EntryType.toFfiConsentEntityType(entryType),
ConsentState.toFfiConsentState(consentType),
value
)
}

private fun FfiConsent.fromFfiConsent(): ConsentListEntry {
return ConsentListEntry(
private fun FfiConsent.fromFfiConsent(): ConsentRecord {
return ConsentRecord(
entity,
EntryType.fromFfiConsentEntityType(entityType),
ConsentState.fromFfiConsentState(state),
Expand Down
Loading