Skip to content

Commit

Permalink
Sync All Conversations Consent Filtering (#353)
Browse files Browse the repository at this point in the history
* bump the code to the latest version

* bump the build as well

* update all the tests for the new async methods

* fix up the lint

* fix up teh test
  • Loading branch information
nplasterer authored Dec 17, 2024
1 parent 25f5a49 commit fbe0420
Show file tree
Hide file tree
Showing 17 changed files with 609 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ConversationsTest {
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
val dm = runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }

val sameDm = boClient.findConversationByTopic(dm.topic)
val sameGroup = boClient.findConversationByTopic(group.topic)
val sameDm = runBlocking { boClient.findConversationByTopic(dm.topic) }
val sameGroup = runBlocking { boClient.findConversationByTopic(group.topic) }
assertEquals(group.id, sameGroup?.id)
assertEquals(dm.id, sameDm?.id)
}
Expand Down Expand Up @@ -112,6 +112,28 @@ class ConversationsTest {
assertEquals(conversationsOrdered.map { it.id }, listOf(group2.id, dm.id, group1.id))
}

@Test
fun testsCanSyncAllConversationsFiltered() {
runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
val group =
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
assertEquals(runBlocking { boClient.conversations.syncAllConversations() }.toInt(), 2)
assertEquals(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt(),
2
)
runBlocking { group.updateConsentState(ConsentState.DENIED) }
assertEquals(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt(),
1
)
assertEquals(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt(),
1
)
assertEquals(runBlocking { boClient.conversations.syncAllConversations() }.toInt(), 2)
}

@Test
fun testCanStreamAllMessages() {
val group =
Expand Down
43 changes: 29 additions & 14 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,19 @@ class DmTest {
runBlocking { dm.send("howdy") }
val messageId = runBlocking { dm.send("gm") }
runBlocking { dm.sync() }
assertEquals(dm.messages().first().body, "gm")
assertEquals(dm.messages().first().id, messageId)
assertEquals(dm.messages().first().deliveryStatus, MessageDeliveryStatus.PUBLISHED)
assertEquals(dm.messages().size, 2)
assertEquals(runBlocking { dm.messages() }.first().body, "gm")
assertEquals(runBlocking { dm.messages() }.first().id, messageId)
assertEquals(
runBlocking { dm.messages() }.first().deliveryStatus,
MessageDeliveryStatus.PUBLISHED
)
assertEquals(runBlocking { dm.messages() }.size, 2)

runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages().size, 2)
assertEquals(sameDm.messages().first().body, "gm")
assertEquals(runBlocking { sameDm.messages() }.size, 2)
assertEquals(runBlocking { sameDm.messages() }.first().body, "gm")
}

@Test
Expand All @@ -215,17 +218,29 @@ class DmTest {
dm.send("gm")
}

assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
assertEquals(runBlocking { dm.messages() }.size, 2)
assertEquals(
runBlocking { dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED) }.size,
2
)
runBlocking { dm.sync() }
assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 0)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
assertEquals(runBlocking { dm.messages() }.size, 2)
assertEquals(
runBlocking { dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED) }.size,
0
)
assertEquals(
runBlocking { dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED) }.size,
2
)

runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
assertEquals(
runBlocking { sameDm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED) }.size,
2
)
}

@Test
Expand All @@ -235,7 +250,7 @@ class DmTest {
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
runBlocking { dm.send("gm") }
runBlocking { dm.sync() }
val messageToReact = dm.messages()[0]
val messageToReact = runBlocking { dm.messages() }[0]

val reaction = Reaction(
reference = messageToReact.id,
Expand All @@ -252,7 +267,7 @@ class DmTest {
}
runBlocking { dm.sync() }

val messages = dm.messages()
val messages = runBlocking { dm.messages() }
assertEquals(messages.size, 2)
val content: Reaction? = messages.first().content()
assertEquals("U+1F603", content?.content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GroupPermissionsTest {

assert(!boGroup.isAdmin(boClient.inboxId))
assert(boGroup.isSuperAdmin(boClient.inboxId))
assert(!alixGroup.isCreator())
assert(!runBlocking { alixGroup.isCreator() })
assert(!alixGroup.isAdmin(alixClient.inboxId))
assert(!alixGroup.isSuperAdmin(alixClient.inboxId))

Expand All @@ -74,13 +74,21 @@ class GroupPermissionsTest {

@Test
fun testGroupCanUpdateAdminList() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
),
GroupPermissionPreconfiguration.ADMIN_ONLY
)
}
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

assert(!boGroup.isAdmin(boClient.inboxId))
assert(boGroup.isSuperAdmin(boClient.inboxId))
assert(!alixGroup.isCreator())
assert(!runBlocking { alixGroup.isCreator() })
assert(!alixGroup.isAdmin(alixClient.inboxId))
assert(!alixGroup.isSuperAdmin(alixClient.inboxId))

Expand Down Expand Up @@ -168,7 +176,15 @@ class GroupPermissionsTest {

@Test
fun testGroupCanUpdateSuperAdminList() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
),
GroupPermissionPreconfiguration.ADMIN_ONLY
)
}
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

Expand Down Expand Up @@ -209,7 +225,15 @@ class GroupPermissionsTest {

@Test
fun testGroupMembersAndPermissionLevel() {
val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
val group = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
),
GroupPermissionPreconfiguration.ADMIN_ONLY
)
}
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

Expand Down Expand Up @@ -258,7 +282,15 @@ class GroupPermissionsTest {

@Test
fun testCanCommitAfterInvalidPermissionsCommit() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ALL_MEMBERS) }
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
),
GroupPermissionPreconfiguration.ALL_MEMBERS
)
}
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

Expand Down Expand Up @@ -289,7 +321,15 @@ class GroupPermissionsTest {

@Test
fun testCanUpdatePermissions() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
),
GroupPermissionPreconfiguration.ADMIN_ONLY
)
}
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

Expand All @@ -305,15 +345,21 @@ class GroupPermissionsTest {
alixGroup.sync()
boGroup.sync()
}
assertEquals(boGroup.permissionPolicySet().updateGroupDescriptionPolicy, PermissionOption.Admin)
assertEquals(
boGroup.permissionPolicySet().updateGroupDescriptionPolicy,
PermissionOption.Admin
)

// Update group name permissions so Alix can update
runBlocking {
boGroup.updateGroupDescriptionPermission(PermissionOption.Allow)
boGroup.sync()
alixGroup.sync()
}
assertEquals(boGroup.permissionPolicySet().updateGroupDescriptionPolicy, PermissionOption.Allow)
assertEquals(
boGroup.permissionPolicySet().updateGroupDescriptionPolicy,
PermissionOption.Allow
)

// Verify that alix can now update group name
runBlocking {
Expand All @@ -327,7 +373,15 @@ class GroupPermissionsTest {

@Test
fun testCanUpdatePinnedFrameUrl() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress, caro.walletAddress), GroupPermissionPreconfiguration.ADMIN_ONLY) }
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
),
GroupPermissionPreconfiguration.ADMIN_ONLY
)
}
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

Expand All @@ -343,15 +397,21 @@ class GroupPermissionsTest {
alixGroup.sync()
boGroup.sync()
}
assertEquals(boGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy, PermissionOption.Admin)
assertEquals(
boGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy,
PermissionOption.Admin
)

// Update group name permissions so Alix can update
runBlocking {
boGroup.updateGroupPinnedFrameUrlPermission(PermissionOption.Allow)
boGroup.sync()
alixGroup.sync()
}
assertEquals(boGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy, PermissionOption.Allow)
assertEquals(
boGroup.permissionPolicySet().updateGroupPinnedFrameUrlPolicy,
PermissionOption.Allow
)

// Verify that alix can now update group name
runBlocking {
Expand Down
Loading

0 comments on commit fbe0420

Please sign in to comment.