@@ -22,7 +22,6 @@ data class ConsentListEntry(
22
22
val value : String ,
23
23
val entryType : EntryType ,
24
24
val consentType : ConsentState ,
25
- val createdAt : Date ,
26
25
) {
27
26
enum class EntryType {
28
27
ADDRESS ,
@@ -33,17 +32,15 @@ data class ConsentListEntry(
33
32
fun address (
34
33
address : String ,
35
34
type : ConsentState = ConsentState .UNKNOWN ,
36
- createdAt : Date = Date (),
37
35
): ConsentListEntry {
38
- return ConsentListEntry (address, EntryType .ADDRESS , type, createdAt )
36
+ return ConsentListEntry (address, EntryType .ADDRESS , type)
39
37
}
40
38
41
39
fun groupId (
42
40
groupId : ByteArray ,
43
41
type : ConsentState = ConsentState .UNKNOWN ,
44
- createdAt : Date = Date (),
45
42
): ConsentListEntry {
46
- return ConsentListEntry (String (groupId), EntryType .GROUP_ID , type, createdAt )
43
+ return ConsentListEntry (String (groupId), EntryType .GROUP_ID , type)
47
44
}
48
45
}
49
46
@@ -55,6 +52,7 @@ class ConsentList(
55
52
val client : Client ,
56
53
val entries : MutableMap <String , ConsentListEntry > = mutableMapOf(),
57
54
) {
55
+ private var lastFetched: Date ? = null
58
56
private val publicKey =
59
57
client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
60
58
private val privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes
@@ -66,17 +64,17 @@ class ConsentList(
66
64
67
65
@OptIn(ExperimentalUnsignedTypes ::class )
68
66
suspend fun load (): List <ConsentListEntry > {
69
- val mostRecent = entries.values.maxOfOrNull { it.createdAt }
70
-
67
+ val newDate = Date ()
71
68
val envelopes =
72
69
client.apiClient.envelopes(
73
70
Topic .preferenceList(identifier).description,
74
71
Pagination (
75
- before = mostRecent ,
72
+ before = lastFetched ,
76
73
direction = MessageApiOuterClass .SortDirection .SORT_DIRECTION_ASCENDING
77
74
),
78
75
)
79
- val preferences: MutableList <Pair <PrivatePreferencesAction , Date >> = mutableListOf ()
76
+ lastFetched = newDate
77
+ val preferences: MutableList <PrivatePreferencesAction > = mutableListOf ()
80
78
for (envelope in envelopes) {
81
79
val payload =
82
80
uniffi.xmtpv3.userPreferencesDecrypt(
@@ -86,26 +84,24 @@ class ConsentList(
86
84
)
87
85
88
86
preferences.add(
89
- Pair (
90
- PrivatePreferencesAction .parseFrom(
91
- payload.toUByteArray().toByteArray(),
92
- ), Date (envelope.timestampNs)
87
+ PrivatePreferencesAction .parseFrom(
88
+ payload.toUByteArray().toByteArray(),
93
89
)
94
90
)
95
91
}
96
92
97
- preferences.iterator().forEach { ( preference, date) ->
93
+ preferences.iterator().forEach { preference ->
98
94
preference.allowAddress?.walletAddressesList?.forEach { address ->
99
- allow(address, date )
95
+ allow(address)
100
96
}
101
97
preference.denyAddress?.walletAddressesList?.forEach { address ->
102
- deny(address, date )
98
+ deny(address)
103
99
}
104
100
preference.allowGroup?.groupIdsList?.forEach { groupId ->
105
- allowGroup(groupId.toByteArray(), date )
101
+ allowGroup(groupId.toByteArray())
106
102
}
107
103
preference.denyGroup?.groupIdsList?.forEach { groupId ->
108
- denyGroup(groupId.toByteArray(), date )
104
+ denyGroup(groupId.toByteArray())
109
105
}
110
106
}
111
107
@@ -171,29 +167,29 @@ class ConsentList(
171
167
client.publish(listOf (envelope))
172
168
}
173
169
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 )
176
172
entries[entry.key] = entry
177
173
178
174
return entry
179
175
}
180
176
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 )
183
179
entries[entry.key] = entry
184
180
185
181
return entry
186
182
}
187
183
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 )
190
186
entries[entry.key] = entry
191
187
192
188
return entry
193
189
}
194
190
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 )
197
193
entries[entry.key] = entry
198
194
199
195
return entry
0 commit comments