Skip to content

Commit 75b624a

Browse files
committed
fix up the caching
1 parent 5adfcbb commit 75b624a

File tree

1 file changed

+32
-25
lines changed
  • library/src/main/java/org/xmtp/android/library

1 file changed

+32
-25
lines changed

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

+32-25
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ data class ConsentListEntry(
2222
val value: String,
2323
val entryType: EntryType,
2424
val consentType: ConsentState,
25-
val createdAt: Date
25+
val createdAt: Date,
2626
) {
2727
enum class EntryType {
2828
ADDRESS,
@@ -33,15 +33,17 @@ data class ConsentListEntry(
3333
fun address(
3434
address: String,
3535
type: ConsentState = ConsentState.UNKNOWN,
36+
createdAt: Date = Date(),
3637
): ConsentListEntry {
37-
return ConsentListEntry(address, EntryType.ADDRESS, type)
38+
return ConsentListEntry(address, EntryType.ADDRESS, type, createdAt)
3839
}
3940

4041
fun groupId(
4142
groupId: ByteArray,
4243
type: ConsentState = ConsentState.UNKNOWN,
44+
createdAt: Date = Date(),
4345
): ConsentListEntry {
44-
return ConsentListEntry(String(groupId), EntryType.GROUP_ID, type)
46+
return ConsentListEntry(String(groupId), EntryType.GROUP_ID, type, createdAt)
4547
}
4648
}
4749

@@ -69,9 +71,12 @@ class ConsentList(
6971
val envelopes =
7072
client.apiClient.envelopes(
7173
Topic.preferenceList(identifier).description,
72-
Pagination(before = mostRecent, direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING),
74+
Pagination(
75+
before = mostRecent,
76+
direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING
77+
),
7378
)
74-
val preferences: MutableList<PrivatePreferencesAction> = mutableListOf()
79+
val preferences: MutableList<Pair<PrivatePreferencesAction, Date>> = mutableListOf()
7580
for (envelope in envelopes) {
7681
val payload =
7782
uniffi.xmtpv3.userPreferencesDecrypt(
@@ -81,24 +86,26 @@ class ConsentList(
8186
)
8287

8388
preferences.add(
84-
PrivatePreferencesAction.parseFrom(
85-
payload.toUByteArray().toByteArray(),
86-
),
89+
Pair(
90+
PrivatePreferencesAction.parseFrom(
91+
payload.toUByteArray().toByteArray(),
92+
), Date(envelope.timestampNs)
93+
)
8794
)
8895
}
8996

90-
preferences.iterator().forEach { preference ->
97+
preferences.iterator().forEach { (preference, date) ->
9198
preference.allowAddress?.walletAddressesList?.forEach { address ->
92-
allow(address)
99+
allow(address, date)
93100
}
94101
preference.denyAddress?.walletAddressesList?.forEach { address ->
95-
deny(address)
102+
deny(address, date)
96103
}
97104
preference.allowGroup?.groupIdsList?.forEach { groupId ->
98-
allowGroup(groupId.toByteArray())
105+
allowGroup(groupId.toByteArray(), date)
99106
}
100107
preference.denyGroup?.groupIdsList?.forEach { groupId ->
101-
denyGroup(groupId.toByteArray())
108+
denyGroup(groupId.toByteArray(), date)
102109
}
103110
}
104111

@@ -164,30 +171,30 @@ class ConsentList(
164171
client.publish(listOf(envelope))
165172
}
166173

167-
fun allow(address: String): ConsentListEntry {
168-
val entry = ConsentListEntry.address(address, ConsentState.ALLOWED)
169-
entries[ConsentListEntry.address(address).key] = entry
174+
fun allow(address: String, date: Date): ConsentListEntry {
175+
val entry = ConsentListEntry.address(address, ConsentState.ALLOWED, date)
176+
entries[entry.key] = entry
170177

171178
return entry
172179
}
173180

174-
fun deny(address: String): ConsentListEntry {
175-
val entry = ConsentListEntry.address(address, ConsentState.DENIED)
176-
entries[ConsentListEntry.address(address).key] = entry
181+
fun deny(address: String, date: Date): ConsentListEntry {
182+
val entry = ConsentListEntry.address(address, ConsentState.DENIED, date)
183+
entries[entry.key] = entry
177184

178185
return entry
179186
}
180187

181-
fun allowGroup(groupId: ByteArray): ConsentListEntry {
182-
val entry = ConsentListEntry.groupId(groupId, ConsentState.ALLOWED)
183-
entries[ConsentListEntry.groupId(groupId).key] = entry
188+
fun allowGroup(groupId: ByteArray, date: Date): ConsentListEntry {
189+
val entry = ConsentListEntry.groupId(groupId, ConsentState.ALLOWED, date)
190+
entries[entry.key] = entry
184191

185192
return entry
186193
}
187194

188-
fun denyGroup(groupId: ByteArray): ConsentListEntry {
189-
val entry = ConsentListEntry.groupId(groupId, ConsentState.DENIED)
190-
entries[ConsentListEntry.groupId(groupId).key] = entry
195+
fun denyGroup(groupId: ByteArray, date: Date): ConsentListEntry {
196+
val entry = ConsentListEntry.groupId(groupId, ConsentState.DENIED, date)
197+
entries[entry.key] = entry
191198

192199
return entry
193200
}

0 commit comments

Comments
 (0)