Skip to content

Commit

Permalink
clean up the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 16, 2024
1 parent 3b43621 commit 6f96e0b
Showing 1 changed file with 31 additions and 54 deletions.
85 changes: 31 additions & 54 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,60 +169,37 @@ class ConsentList(
if (client.hasV2Client) {
val payload = PrivatePreferencesAction.newBuilder().also {
entries.iterator().forEach { entry ->
when (entry.entryType) {
EntryType.ADDRESS -> {
when (entry.consentType) {
ConsentState.ALLOWED ->
it.setAllowAddress(
PrivatePreferencesAction.AllowAddress.newBuilder()
.addWalletAddresses(entry.value),
)

ConsentState.DENIED ->
it.setDenyAddress(
PrivatePreferencesAction.DenyAddress.newBuilder()
.addWalletAddresses(entry.value),
)

ConsentState.UNKNOWN -> it.clearMessageType()
}
}

EntryType.GROUP_ID -> {
when (entry.consentType) {
ConsentState.ALLOWED ->
it.setAllowGroup(
PrivatePreferencesAction.AllowGroup.newBuilder()
.addGroupIds(entry.value),
)

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

ConsentState.UNKNOWN -> it.clearMessageType()
}
}

EntryType.INBOX_ID -> {
when (entry.consentType) {
ConsentState.ALLOWED ->
it.setAllowInboxId(
PrivatePreferencesAction.AllowInboxId.newBuilder()
.addInboxIds(entry.value),
)

ConsentState.DENIED ->
it.setDenyInboxId(
PrivatePreferencesAction.DenyInboxId.newBuilder()
.addInboxIds(entry.value),
)

ConsentState.UNKNOWN -> it.clearMessageType()
}
}
when (entry.entryType to entry.consentType) {
EntryType.ADDRESS to ConsentState.ALLOWED -> it.setAllowAddress(
PrivatePreferencesAction.AllowAddress.newBuilder()
.addWalletAddresses(entry.value)
)

EntryType.ADDRESS to ConsentState.DENIED -> it.setDenyAddress(
PrivatePreferencesAction.DenyAddress.newBuilder()
.addWalletAddresses(entry.value)
)

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

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

EntryType.INBOX_ID to ConsentState.ALLOWED -> it.setAllowInboxId(
PrivatePreferencesAction.AllowInboxId.newBuilder()
.addInboxIds(entry.value)
)

EntryType.INBOX_ID to ConsentState.DENIED -> it.setDenyInboxId(
PrivatePreferencesAction.DenyInboxId.newBuilder()
.addInboxIds(entry.value)
)

else -> it.clearMessageType()
}
}
}.build()
Expand Down

0 comments on commit 6f96e0b

Please sign in to comment.