Skip to content

Commit 51c7b17

Browse files
authored
Consent filtering by array (#371)
* reformat the file * undo formatting * consent filtering * turn off history sync * add the inboxid functions * write a bunch of tests * add test for last message * small rename clean up * fix up read reciepts test
1 parent 9ec2055 commit 51c7b17

File tree

14 files changed

+1111
-762
lines changed

14 files changed

+1111
-762
lines changed

library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt

+52-7
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,29 @@ class ConversationsTest {
7878
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
7979
assertEquals(runBlocking { boClient.conversations.list().size }, 2)
8080
assertEquals(
81-
runBlocking { boClient.conversations.list(consentState = ConsentState.ALLOWED).size },
81+
runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.ALLOWED)).size },
8282
2
8383
)
8484
runBlocking { group.updateConsentState(ConsentState.DENIED) }
8585
assertEquals(
86-
runBlocking { boClient.conversations.list(consentState = ConsentState.ALLOWED).size },
86+
runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.ALLOWED)).size },
8787
1
8888
)
8989
assertEquals(
90-
runBlocking { boClient.conversations.list(consentState = ConsentState.DENIED).size },
90+
runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.DENIED)).size },
9191
1
9292
)
93+
assertEquals(
94+
runBlocking {
95+
boClient.conversations.list(
96+
consentStates = listOf(
97+
ConsentState.DENIED,
98+
ConsentState.ALLOWED
99+
)
100+
).size
101+
},
102+
2
103+
)
93104
assertEquals(runBlocking { boClient.conversations.list().size }, 2)
94105
}
95106

@@ -119,17 +130,51 @@ class ConversationsTest {
119130
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
120131
assert(runBlocking { boClient.conversations.syncAllConversations() }.toInt() >= 2)
121132
assert(
122-
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt() >= 2
133+
runBlocking {
134+
boClient.conversations.syncAllConversations(
135+
consentStates = listOf(
136+
ConsentState.ALLOWED
137+
)
138+
)
139+
}.toInt() >= 2
123140
)
124141
assert(
125-
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt() <= 1
142+
runBlocking {
143+
boClient.conversations.syncAllConversations(
144+
consentStates = listOf(
145+
ConsentState.DENIED
146+
)
147+
)
148+
}.toInt() <= 1
126149
)
127150
runBlocking { group.updateConsentState(ConsentState.DENIED) }
128151
assert(
129-
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt() <= 2
152+
runBlocking {
153+
boClient.conversations.syncAllConversations(
154+
consentStates = listOf(
155+
ConsentState.ALLOWED
156+
)
157+
)
158+
}.toInt() <= 2
159+
)
160+
assert(
161+
runBlocking {
162+
boClient.conversations.syncAllConversations(
163+
consentStates = listOf(
164+
ConsentState.DENIED
165+
)
166+
)
167+
}.toInt() <= 2
130168
)
131169
assert(
132-
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt() <= 2
170+
runBlocking {
171+
boClient.conversations.syncAllConversations(
172+
consentStates = listOf(
173+
ConsentState.DENIED,
174+
ConsentState.ALLOWED
175+
)
176+
)
177+
}.toInt() >= 2
133178
)
134179
assert(runBlocking { boClient.conversations.syncAllConversations() }.toInt() >= 2)
135180
}

library/src/androidTest/java/org/xmtp/android/library/DmTest.kt

+24-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ class DmTest {
6161
}
6262
}
6363

64+
@Test
65+
fun testCanCreateADmWithInboxId() {
66+
runBlocking {
67+
val convo1 = boClient.conversations.findOrCreateDmWithInboxId(alixClient.inboxId)
68+
alixClient.conversations.sync()
69+
val sameConvo1 = alixClient.conversations.findOrCreateDmWithInboxId(boClient.inboxId)
70+
assertEquals(convo1.id, sameConvo1.id)
71+
}
72+
}
73+
6474
@Test
6575
fun testsCanFindDmByInboxId() {
6676
runBlocking {
@@ -156,18 +166,29 @@ class DmTest {
156166
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
157167
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
158168
assertEquals(
159-
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
169+
runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.ALLOWED)).size },
160170
2
161171
)
162172
runBlocking { dm.updateConsentState(ConsentState.DENIED) }
163173
assertEquals(
164-
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
174+
runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.ALLOWED)).size },
165175
1
166176
)
167177
assertEquals(
168-
runBlocking { boClient.conversations.listDms(consentState = ConsentState.DENIED).size },
178+
runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.DENIED)).size },
169179
1
170180
)
181+
assertEquals(
182+
runBlocking {
183+
boClient.conversations.listDms(
184+
consentStates = listOf(
185+
ConsentState.ALLOWED,
186+
ConsentState.DENIED
187+
)
188+
).size
189+
},
190+
2
191+
)
171192
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
172193
}
173194

library/src/androidTest/java/org/xmtp/android/library/GroupPermissionsTest.kt

+34
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,38 @@ class GroupPermissionsTest {
506506
runBlocking { alixClient.conversations.sync() }
507507
assert(runBlocking { alixClient.conversations.listGroups() }.size == 1)
508508
}
509+
510+
@Test
511+
fun canCreateGroupWithInboxIdCustomPermissions() {
512+
val permissionPolicySet = PermissionPolicySet(
513+
addMemberPolicy = PermissionOption.Admin,
514+
removeMemberPolicy = PermissionOption.Deny,
515+
addAdminPolicy = PermissionOption.Admin,
516+
removeAdminPolicy = PermissionOption.SuperAdmin,
517+
updateGroupNamePolicy = PermissionOption.Admin,
518+
updateGroupDescriptionPolicy = PermissionOption.Allow,
519+
updateGroupImagePolicy = PermissionOption.Admin,
520+
updateGroupPinnedFrameUrlPolicy = PermissionOption.Deny,
521+
updateMessageExpirationPolicy = PermissionOption.Admin,
522+
)
523+
val boGroup = runBlocking {
524+
boClient.conversations.newGroupCustomPermissionsWithInboxIds(
525+
inboxIds = listOf(alixClient.inboxId, caroClient.inboxId),
526+
permissionPolicySet = permissionPolicySet,
527+
)
528+
}
529+
runBlocking { alixClient.conversations.sync() }
530+
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }
531+
532+
// Verify permission look correct
533+
val alixPermissionSet = alixGroup.permissionPolicySet()
534+
assert(alixPermissionSet.addMemberPolicy == PermissionOption.Admin)
535+
assert(alixPermissionSet.removeMemberPolicy == PermissionOption.Deny)
536+
assert(alixPermissionSet.addAdminPolicy == PermissionOption.Admin)
537+
assert(alixPermissionSet.removeAdminPolicy == PermissionOption.SuperAdmin)
538+
assert(alixPermissionSet.updateGroupNamePolicy == PermissionOption.Admin)
539+
assert(alixPermissionSet.updateGroupDescriptionPolicy == PermissionOption.Allow)
540+
assert(alixPermissionSet.updateGroupImagePolicy == PermissionOption.Admin)
541+
assert(alixPermissionSet.updateGroupPinnedFrameUrlPolicy == PermissionOption.Deny)
542+
}
509543
}

library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt

+54-3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,46 @@ class GroupTest {
164164
assert(!runBlocking { alixGroup.isCreator() })
165165
}
166166

167+
@Test
168+
fun testCanCreateAGroupWithInboxIdsDefaultPermissions() {
169+
val boGroup = runBlocking {
170+
boClient.conversations.newGroupWithInboxIds(listOf(alixClient.inboxId))
171+
}
172+
runBlocking {
173+
alixClient.conversations.sync()
174+
boGroup.sync()
175+
}
176+
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }
177+
assert(boGroup.id.isNotEmpty())
178+
assert(alixGroup.id.isNotEmpty())
179+
180+
runBlocking {
181+
alixGroup.addMembers(listOf(caro.walletAddress))
182+
boGroup.sync()
183+
}
184+
assertEquals(runBlocking { alixGroup.members().size }, 3)
185+
assertEquals(runBlocking { boGroup.members().size }, 3)
186+
187+
// All members also defaults remove to admin only now.
188+
assertThrows(XMTPException::class.java) {
189+
runBlocking {
190+
alixGroup.removeMembers(listOf(caro.walletAddress))
191+
boGroup.sync()
192+
}
193+
}
194+
195+
assertEquals(runBlocking { alixGroup.members().size }, 3)
196+
assertEquals(runBlocking { boGroup.members().size }, 3)
197+
198+
assertEquals(boGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow)
199+
assertEquals(alixGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow)
200+
assertEquals(boGroup.isSuperAdmin(boClient.inboxId), true)
201+
assertEquals(boGroup.isSuperAdmin(alixClient.inboxId), false)
202+
assertEquals(alixGroup.isSuperAdmin(boClient.inboxId), true)
203+
assertEquals(alixGroup.isSuperAdmin(alixClient.inboxId), false)
204+
assert(!runBlocking { alixGroup.isCreator() })
205+
}
206+
167207
@Test
168208
fun testCanListGroupMembers() {
169209
val group = runBlocking {
@@ -488,18 +528,29 @@ class GroupTest {
488528
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
489529
assertEquals(runBlocking { boClient.conversations.listGroups().size }, 2)
490530
assertEquals(
491-
runBlocking { boClient.conversations.listGroups(consentState = ConsentState.ALLOWED).size },
531+
runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.ALLOWED)).size },
492532
2
493533
)
494534
runBlocking { group.updateConsentState(ConsentState.DENIED) }
495535
assertEquals(
496-
runBlocking { boClient.conversations.listGroups(consentState = ConsentState.ALLOWED).size },
536+
runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.ALLOWED)).size },
497537
1
498538
)
499539
assertEquals(
500-
runBlocking { boClient.conversations.listGroups(consentState = ConsentState.DENIED).size },
540+
runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.DENIED)).size },
501541
1
502542
)
543+
assertEquals(
544+
runBlocking {
545+
boClient.conversations.listGroups(
546+
consentStates = listOf(
547+
ConsentState.ALLOWED,
548+
ConsentState.DENIED
549+
)
550+
).size
551+
},
552+
2
553+
)
503554
assertEquals(runBlocking { boClient.conversations.listGroups().size }, 2)
504555
}
505556

library/src/androidTest/java/org/xmtp/android/library/ReadReceiptTest.kt

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,31 @@ class ReadReceiptTest {
1818
Client.register(codec = ReadReceiptCodec())
1919

2020
val fixtures = fixtures()
21-
val aliceClient = fixtures.alixClient
22-
val aliceConversation = runBlocking {
23-
aliceClient.conversations.newConversation(fixtures.bo.walletAddress)
21+
val alixClient = fixtures.alixClient
22+
val alixConversation = runBlocking {
23+
alixClient.conversations.newConversation(fixtures.bo.walletAddress)
2424
}
2525

26-
runBlocking { aliceConversation.send(text = "hey alice 2 bob") }
26+
runBlocking { alixConversation.send(text = "hey alice 2 bob") }
2727

2828
val readReceipt = ReadReceipt
2929

3030
runBlocking {
31-
aliceConversation.send(
31+
alixConversation.send(
3232
content = readReceipt,
3333
options = SendOptions(contentType = ContentTypeReadReceipt),
3434
)
3535
}
36-
val messages = runBlocking { aliceConversation.messages() }
36+
val messages = runBlocking { alixConversation.messages() }
3737
assertEquals(messages.size, 2)
3838
if (messages.size == 2) {
3939
val contentType: String = messages.first().encodedContent.type.typeId
4040
assertEquals(contentType, "readReceipt")
4141
}
42+
val convos = runBlocking { alixClient.conversations.list() }
43+
assertEquals(
44+
runBlocking { convos.first().lastMessage() }!!.encodedContent.type.typeId,
45+
"text"
46+
)
4247
}
4348
}

library/src/main/java/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ Kotlin code emitted by the `bindings_ffi` crate in [libxmtp](https://github.com/
77
1. From repo [libxmtp](https://github.com/xmtp/libxmtp) run the [kotlin release action](https://github.com/xmtp/libxmtp/actions/workflows/release-kotlin-bindings.yml) for the branch you desire (this should take about 4 minutes)
88
2. Once you see the [kotlin bindings GitHub action](https://github.com/xmtp/libxmtp/actions/workflows/release-kotlin-bindings.yml) is finished, with `libxmtp` repo and `xmtp-android` (this repo) cloned locally in sibling directories, and `libxmtp` checked out to the correct release commit, run the script:
99
`./gen_kotlin.sh` within the `bindings_ffi` folder.
10-
3. **(If only testing, you can skip this step**)Run format (cmd + opt + l) function to keep the code format consistent and diff small for `xmtp-android/library/src/main/java/xmtpv3.kt`
1110

1211
You should now be on the latest libxmtp. Tests will fail if the jniLibs do not match the version of xmtpv3.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: f04e0049
1+
Version: fc37819c
22
Branch: main
3-
Date: 2025-01-14 23:09:48 +0000
3+
Date: 2025-01-17 01:38:53 +0000

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ data class ClientOptions(
2727
val preAuthenticateToInboxCallback: PreEventCallback? = null,
2828
val appContext: Context,
2929
val dbEncryptionKey: ByteArray,
30-
val historySyncUrl: String = when (api.env) {
31-
XMTPEnvironment.PRODUCTION -> "https://message-history.production.ephemera.network/"
32-
XMTPEnvironment.LOCAL -> "http://10.0.2.2:5558"
33-
else -> "https://message-history.dev.ephemera.network/"
34-
},
30+
val historySyncUrl: String? = null,
3531
val dbDirectory: String? = null,
3632
) {
3733
data class Api(

0 commit comments

Comments
 (0)