Skip to content

Commit 1377775

Browse files
committed
fix: runs ktlint on Contacts.kt
1 parent b231c00 commit 1377775

File tree

1 file changed

+66
-59
lines changed
  • library/src/main/java/org/xmtp/android/library

1 file changed

+66
-59
lines changed

library/src/main/java/org/xmtp/android/library/Contacts.kt

+66-59
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java.util.Date
1515
enum class ConsentState {
1616
ALLOWED,
1717
DENIED,
18-
UNKNOWN
18+
UNKNOWN,
1919
}
2020

2121
data class ConsentListEntry(
@@ -25,7 +25,7 @@ data class ConsentListEntry(
2525
) {
2626
enum class EntryType {
2727
ADDRESS,
28-
GROUP_ID
28+
GROUP_ID,
2929
}
3030

3131
companion object {
@@ -54,29 +54,32 @@ class ConsentList(val client: Client) {
5454
client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
5555
private val privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes
5656

57-
private val identifier: String = uniffi.xmtpv3.generatePrivatePreferencesTopicIdentifier(
58-
privateKey.toByteArray()
59-
)
57+
private val identifier: String =
58+
uniffi.xmtpv3.generatePrivatePreferencesTopicIdentifier(
59+
privateKey.toByteArray(),
60+
)
6061

6162
@OptIn(ExperimentalUnsignedTypes::class)
6263
suspend fun load(): ConsentList {
63-
val envelopes = client.apiClient.envelopes(
64-
Topic.preferenceList(identifier).description,
65-
Pagination(direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING)
66-
)
64+
val envelopes =
65+
client.apiClient.envelopes(
66+
Topic.preferenceList(identifier).description,
67+
Pagination(direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING),
68+
)
6769
val consentList = ConsentList(client)
6870
val preferences: MutableList<PrivatePreferencesAction> = mutableListOf()
6971
for (envelope in envelopes) {
70-
val payload = uniffi.xmtpv3.userPreferencesDecrypt(
71-
publicKey.toByteArray(),
72-
privateKey.toByteArray(),
73-
envelope.message.toByteArray()
74-
)
72+
val payload =
73+
uniffi.xmtpv3.userPreferencesDecrypt(
74+
publicKey.toByteArray(),
75+
privateKey.toByteArray(),
76+
envelope.message.toByteArray(),
77+
)
7578

7679
preferences.add(
7780
PrivatePreferencesAction.parseFrom(
78-
payload.toUByteArray().toByteArray()
79-
)
81+
payload.toUByteArray().toByteArray(),
82+
),
8083
)
8184
}
8285

@@ -99,48 +102,55 @@ class ConsentList(val client: Client) {
99102
}
100103

101104
fun publish(entry: ConsentListEntry) {
102-
val payload = PrivatePreferencesAction.newBuilder().also {
103-
when (entry.entryType) {
104-
ConsentListEntry.EntryType.ADDRESS -> {
105-
when (entry.consentType) {
106-
ConsentState.ALLOWED -> it.setAllowDm(
107-
PrivatePreferencesAction.AllowDM.newBuilder().addWalletAddresses(entry.value)
108-
)
109-
110-
ConsentState.DENIED -> it.setDenyDm(
111-
PrivatePreferencesAction.DenyDM.newBuilder().addWalletAddresses(entry.value)
112-
)
113-
114-
ConsentState.UNKNOWN -> it.clearMessageType()
105+
val payload =
106+
PrivatePreferencesAction.newBuilder().also {
107+
when (entry.entryType) {
108+
ConsentListEntry.EntryType.ADDRESS -> {
109+
when (entry.consentType) {
110+
ConsentState.ALLOWED ->
111+
it.setAllowDm(
112+
PrivatePreferencesAction.AllowDM.newBuilder().addWalletAddresses(entry.value),
113+
)
114+
115+
ConsentState.DENIED ->
116+
it.setDenyDm(
117+
PrivatePreferencesAction.DenyDM.newBuilder().addWalletAddresses(entry.value),
118+
)
119+
120+
ConsentState.UNKNOWN -> it.clearMessageType()
121+
}
115122
}
116-
}
117-
ConsentListEntry.EntryType.GROUP_ID -> {
118-
when (entry.consentType) {
119-
ConsentState.ALLOWED -> it.setAllowGroup(
120-
PrivatePreferencesAction.AllowGroup.newBuilder().addGroupIds(entry.value.toByteStringUtf8())
121-
)
122-
123-
ConsentState.DENIED -> it.setDenyGroup(
124-
PrivatePreferencesAction.DenyGroup.newBuilder().addGroupIds(entry.value.toByteStringUtf8())
125-
)
126-
127-
ConsentState.UNKNOWN -> it.clearMessageType()
123+
ConsentListEntry.EntryType.GROUP_ID -> {
124+
when (entry.consentType) {
125+
ConsentState.ALLOWED ->
126+
it.setAllowGroup(
127+
PrivatePreferencesAction.AllowGroup.newBuilder().addGroupIds(entry.value.toByteStringUtf8()),
128+
)
129+
130+
ConsentState.DENIED ->
131+
it.setDenyGroup(
132+
PrivatePreferencesAction.DenyGroup.newBuilder().addGroupIds(entry.value.toByteStringUtf8()),
133+
)
134+
135+
ConsentState.UNKNOWN -> it.clearMessageType()
136+
}
128137
}
129138
}
130-
}
131-
}.build()
139+
}.build()
132140

133-
val message = uniffi.xmtpv3.userPreferencesEncrypt(
134-
publicKey.toByteArray(),
135-
privateKey.toByteArray(),
136-
payload.toByteArray()
137-
)
141+
val message =
142+
uniffi.xmtpv3.userPreferencesEncrypt(
143+
publicKey.toByteArray(),
144+
privateKey.toByteArray(),
145+
payload.toByteArray(),
146+
)
138147

139-
val envelope = EnvelopeBuilder.buildFromTopic(
140-
Topic.preferenceList(identifier),
141-
Date(),
142-
ByteArray(message.size) { message[it].toByte() }
143-
)
148+
val envelope =
149+
EnvelopeBuilder.buildFromTopic(
150+
Topic.preferenceList(identifier),
151+
Date(),
152+
ByteArray(message.size) { message[it].toByte() },
153+
)
144154

145155
client.publish(listOf(envelope))
146156
}
@@ -178,7 +188,7 @@ class ConsentList(val client: Client) {
178188

179189
return entry?.consentType ?: ConsentState.UNKNOWN
180190
}
181-
191+
182192
fun groupState(groupId: ByteArray): ConsentState {
183193
val entry = entries[ConsentListEntry.groupId(groupId).key]
184194

@@ -191,7 +201,6 @@ data class Contacts(
191201
val knownBundles: MutableMap<String, ContactBundle> = mutableMapOf(),
192202
val hasIntroduced: MutableMap<String, Boolean> = mutableMapOf(),
193203
) {
194-
195204
var consentList: ConsentList = ConsentList(client)
196205

197206
fun refreshConsentList(): ConsentList {
@@ -241,11 +250,9 @@ data class Contacts(
241250
return consentList.groupState(groupId) == ConsentState.DENIED
242251
}
243252

244-
fun has(peerAddress: String): Boolean =
245-
knownBundles[peerAddress] != null
253+
fun has(peerAddress: String): Boolean = knownBundles[peerAddress] != null
246254

247-
fun needsIntroduction(peerAddress: String): Boolean =
248-
hasIntroduced[peerAddress] != true
255+
fun needsIntroduction(peerAddress: String): Boolean = hasIntroduced[peerAddress] != true
249256

250257
fun find(peerAddress: String): ContactBundle? {
251258
val knownBundle = knownBundles[peerAddress]

0 commit comments

Comments
 (0)