@@ -4,14 +4,16 @@ import kotlinx.coroutines.runBlocking
4
4
import org.xmtp.android.library.messages.ContactBundle
5
5
import org.xmtp.android.library.messages.ContactBundleBuilder
6
6
import org.xmtp.android.library.messages.EnvelopeBuilder
7
+ import org.xmtp.android.library.messages.Pagination
7
8
import org.xmtp.android.library.messages.Topic
8
9
import org.xmtp.android.library.messages.walletAddress
10
+ import org.xmtp.proto.message.api.v1.MessageApiOuterClass
9
11
import org.xmtp.proto.message.contents.PrivatePreferences.PrivatePreferencesAction
10
12
import java.util.Date
11
13
12
14
enum class ConsentState {
13
15
ALLOWED ,
14
- BLOCKED ,
16
+ DENIED ,
15
17
UNKNOWN
16
18
}
17
19
@@ -50,7 +52,10 @@ class ConsentList(val client: Client) {
50
52
51
53
@OptIn(ExperimentalUnsignedTypes ::class )
52
54
suspend fun load (): ConsentList {
53
- val envelopes = client.query(Topic .preferenceList(identifier))
55
+ val envelopes = client.query(
56
+ Topic .preferenceList(identifier),
57
+ Pagination (direction = MessageApiOuterClass .SortDirection .SORT_DIRECTION_ASCENDING )
58
+ )
54
59
val consentList = ConsentList (client)
55
60
val preferences: MutableList <PrivatePreferencesAction > = mutableListOf ()
56
61
@@ -68,12 +73,12 @@ class ConsentList(val client: Client) {
68
73
)
69
74
}
70
75
71
- preferences.reversed(). iterator().forEach { preference ->
76
+ preferences.iterator().forEach { preference ->
72
77
preference.allow?.walletAddressesList?.forEach { address ->
73
78
consentList.allow(address)
74
79
}
75
80
preference.block?.walletAddressesList?.forEach { address ->
76
- consentList.block (address)
81
+ consentList.deny (address)
77
82
}
78
83
}
79
84
@@ -88,7 +93,7 @@ class ConsentList(val client: Client) {
88
93
PrivatePreferencesAction .Allow .newBuilder().addWalletAddresses(entry.value)
89
94
)
90
95
91
- ConsentState .BLOCKED -> it.setBlock(
96
+ ConsentState .DENIED -> it.setBlock(
92
97
PrivatePreferencesAction .Block .newBuilder().addWalletAddresses(entry.value)
93
98
)
94
99
@@ -117,10 +122,10 @@ class ConsentList(val client: Client) {
117
122
return ConsentListEntry .address(address, ConsentState .ALLOWED )
118
123
}
119
124
120
- fun block (address : String ): ConsentListEntry {
121
- entries[ConsentListEntry .address(address).key] = ConsentState .BLOCKED
125
+ fun deny (address : String ): ConsentListEntry {
126
+ entries[ConsentListEntry .address(address).key] = ConsentState .DENIED
122
127
123
- return ConsentListEntry .address(address, ConsentState .BLOCKED )
128
+ return ConsentListEntry .address(address, ConsentState .DENIED )
124
129
}
125
130
126
131
fun state (address : String ): ConsentState {
@@ -148,8 +153,8 @@ data class Contacts(
148
153
return consentList.state(address) == ConsentState .ALLOWED
149
154
}
150
155
151
- fun isBlocked (address : String ): Boolean {
152
- return consentList.state(address) == ConsentState .BLOCKED
156
+ fun isDenied (address : String ): Boolean {
157
+ return consentList.state(address) == ConsentState .DENIED
153
158
}
154
159
155
160
fun allow (addresses : List <String >) {
@@ -158,9 +163,9 @@ data class Contacts(
158
163
}
159
164
}
160
165
161
- fun block (addresses : List <String >) {
166
+ fun deny (addresses : List <String >) {
162
167
for (address in addresses) {
163
- ConsentList (client).publish(consentList.block (address))
168
+ ConsentList (client).publish(consentList.deny (address))
164
169
}
165
170
}
166
171
0 commit comments