Skip to content

Commit 1c57187

Browse files
committed
set just one date
1 parent 75b624a commit 1c57187

File tree

1 file changed

+22
-26
lines changed
  • library/src/main/java/org/xmtp/android/library

1 file changed

+22
-26
lines changed

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

+22-26
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ data class ConsentListEntry(
2222
val value: String,
2323
val entryType: EntryType,
2424
val consentType: ConsentState,
25-
val createdAt: Date,
2625
) {
2726
enum class EntryType {
2827
ADDRESS,
@@ -33,17 +32,15 @@ data class ConsentListEntry(
3332
fun address(
3433
address: String,
3534
type: ConsentState = ConsentState.UNKNOWN,
36-
createdAt: Date = Date(),
3735
): ConsentListEntry {
38-
return ConsentListEntry(address, EntryType.ADDRESS, type, createdAt)
36+
return ConsentListEntry(address, EntryType.ADDRESS, type)
3937
}
4038

4139
fun groupId(
4240
groupId: ByteArray,
4341
type: ConsentState = ConsentState.UNKNOWN,
44-
createdAt: Date = Date(),
4542
): ConsentListEntry {
46-
return ConsentListEntry(String(groupId), EntryType.GROUP_ID, type, createdAt)
43+
return ConsentListEntry(String(groupId), EntryType.GROUP_ID, type)
4744
}
4845
}
4946

@@ -55,6 +52,7 @@ class ConsentList(
5552
val client: Client,
5653
val entries: MutableMap<String, ConsentListEntry> = mutableMapOf(),
5754
) {
55+
private var lastFetched: Date? = null
5856
private val publicKey =
5957
client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
6058
private val privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes
@@ -66,17 +64,17 @@ class ConsentList(
6664

6765
@OptIn(ExperimentalUnsignedTypes::class)
6866
suspend fun load(): List<ConsentListEntry> {
69-
val mostRecent = entries.values.maxOfOrNull { it.createdAt }
70-
67+
val newDate = Date()
7168
val envelopes =
7269
client.apiClient.envelopes(
7370
Topic.preferenceList(identifier).description,
7471
Pagination(
75-
before = mostRecent,
72+
before = lastFetched,
7673
direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING
7774
),
7875
)
79-
val preferences: MutableList<Pair<PrivatePreferencesAction, Date>> = mutableListOf()
76+
lastFetched = newDate
77+
val preferences: MutableList<PrivatePreferencesAction> = mutableListOf()
8078
for (envelope in envelopes) {
8179
val payload =
8280
uniffi.xmtpv3.userPreferencesDecrypt(
@@ -86,26 +84,24 @@ class ConsentList(
8684
)
8785

8886
preferences.add(
89-
Pair(
90-
PrivatePreferencesAction.parseFrom(
91-
payload.toUByteArray().toByteArray(),
92-
), Date(envelope.timestampNs)
87+
PrivatePreferencesAction.parseFrom(
88+
payload.toUByteArray().toByteArray(),
9389
)
9490
)
9591
}
9692

97-
preferences.iterator().forEach { (preference, date) ->
93+
preferences.iterator().forEach { preference ->
9894
preference.allowAddress?.walletAddressesList?.forEach { address ->
99-
allow(address, date)
95+
allow(address)
10096
}
10197
preference.denyAddress?.walletAddressesList?.forEach { address ->
102-
deny(address, date)
98+
deny(address)
10399
}
104100
preference.allowGroup?.groupIdsList?.forEach { groupId ->
105-
allowGroup(groupId.toByteArray(), date)
101+
allowGroup(groupId.toByteArray())
106102
}
107103
preference.denyGroup?.groupIdsList?.forEach { groupId ->
108-
denyGroup(groupId.toByteArray(), date)
104+
denyGroup(groupId.toByteArray())
109105
}
110106
}
111107

@@ -171,29 +167,29 @@ class ConsentList(
171167
client.publish(listOf(envelope))
172168
}
173169

174-
fun allow(address: String, date: Date): ConsentListEntry {
175-
val entry = ConsentListEntry.address(address, ConsentState.ALLOWED, date)
170+
fun allow(address: String): ConsentListEntry {
171+
val entry = ConsentListEntry.address(address, ConsentState.ALLOWED)
176172
entries[entry.key] = entry
177173

178174
return entry
179175
}
180176

181-
fun deny(address: String, date: Date): ConsentListEntry {
182-
val entry = ConsentListEntry.address(address, ConsentState.DENIED, date)
177+
fun deny(address: String): ConsentListEntry {
178+
val entry = ConsentListEntry.address(address, ConsentState.DENIED)
183179
entries[entry.key] = entry
184180

185181
return entry
186182
}
187183

188-
fun allowGroup(groupId: ByteArray, date: Date): ConsentListEntry {
189-
val entry = ConsentListEntry.groupId(groupId, ConsentState.ALLOWED, date)
184+
fun allowGroup(groupId: ByteArray): ConsentListEntry {
185+
val entry = ConsentListEntry.groupId(groupId, ConsentState.ALLOWED)
190186
entries[entry.key] = entry
191187

192188
return entry
193189
}
194190

195-
fun denyGroup(groupId: ByteArray, date: Date): ConsentListEntry {
196-
val entry = ConsentListEntry.groupId(groupId, ConsentState.DENIED, date)
191+
fun denyGroup(groupId: ByteArray): ConsentListEntry {
192+
val entry = ConsentListEntry.groupId(groupId, ConsentState.DENIED)
197193
entries[entry.key] = entry
198194

199195
return entry

0 commit comments

Comments
 (0)