Skip to content

Commit

Permalink
Merge branch 'main' into cv/01-09-reaction_v2_and_list_messages_with_…
Browse files Browse the repository at this point in the history
…reactions
  • Loading branch information
cameronvoell committed Jan 17, 2025
2 parents d150b91 + 51c7b17 commit e6375f6
Show file tree
Hide file tree
Showing 19 changed files with 3,965 additions and 4,941 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class ClientTest {
notOnNetwork.address,
fixtures.bo.walletAddress
),
context,
ClientOptions.Api(XMTPEnvironment.LOCAL, false)
)
}
Expand All @@ -109,7 +108,6 @@ class ClientTest {
val states = runBlocking {
Client.inboxStatesForInboxIds(
listOf(fixtures.boClient.inboxId, fixtures.caroClient.inboxId),
context,
ClientOptions.Api(XMTPEnvironment.LOCAL, false)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,29 @@ class ConversationsTest {
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
assertEquals(runBlocking { boClient.conversations.list().size }, 2)
assertEquals(
runBlocking { boClient.conversations.list(consentState = ConsentState.ALLOWED).size },
runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.ALLOWED)).size },
2
)
runBlocking { group.updateConsentState(ConsentState.DENIED) }
assertEquals(
runBlocking { boClient.conversations.list(consentState = ConsentState.ALLOWED).size },
runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.ALLOWED)).size },
1
)
assertEquals(
runBlocking { boClient.conversations.list(consentState = ConsentState.DENIED).size },
runBlocking { boClient.conversations.list(consentStates = listOf(ConsentState.DENIED)).size },
1
)
assertEquals(
runBlocking {
boClient.conversations.list(
consentStates = listOf(
ConsentState.DENIED,
ConsentState.ALLOWED
)
).size
},
2
)
assertEquals(runBlocking { boClient.conversations.list().size }, 2)
}

Expand Down Expand Up @@ -119,17 +130,51 @@ class ConversationsTest {
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
assert(runBlocking { boClient.conversations.syncAllConversations() }.toInt() >= 2)
assert(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt() >= 2
runBlocking {
boClient.conversations.syncAllConversations(
consentStates = listOf(
ConsentState.ALLOWED
)
)
}.toInt() >= 2
)
assert(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt() <= 1
runBlocking {
boClient.conversations.syncAllConversations(
consentStates = listOf(
ConsentState.DENIED
)
)
}.toInt() <= 1
)
runBlocking { group.updateConsentState(ConsentState.DENIED) }
assert(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt() <= 2
runBlocking {
boClient.conversations.syncAllConversations(
consentStates = listOf(
ConsentState.ALLOWED
)
)
}.toInt() <= 2
)
assert(
runBlocking {
boClient.conversations.syncAllConversations(
consentStates = listOf(
ConsentState.DENIED
)
)
}.toInt() <= 2
)
assert(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt() <= 2
runBlocking {
boClient.conversations.syncAllConversations(
consentStates = listOf(
ConsentState.DENIED,
ConsentState.ALLOWED
)
)
}.toInt() >= 2
)
assert(runBlocking { boClient.conversations.syncAllConversations() }.toInt() >= 2)
}
Expand Down
27 changes: 24 additions & 3 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ class DmTest {
}
}

@Test
fun testCanCreateADmWithInboxId() {
runBlocking {
val convo1 = boClient.conversations.findOrCreateDmWithInboxId(alixClient.inboxId)
alixClient.conversations.sync()
val sameConvo1 = alixClient.conversations.findOrCreateDmWithInboxId(boClient.inboxId)
assertEquals(convo1.id, sameConvo1.id)
}
}

@Test
fun testsCanFindDmByInboxId() {
runBlocking {
Expand Down Expand Up @@ -156,18 +166,29 @@ class DmTest {
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.ALLOWED)).size },
2
)
runBlocking { dm.updateConsentState(ConsentState.DENIED) }
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.ALLOWED)).size },
1
)
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.DENIED).size },
runBlocking { boClient.conversations.listDms(consentStates = listOf(ConsentState.DENIED)).size },
1
)
assertEquals(
runBlocking {
boClient.conversations.listDms(
consentStates = listOf(
ConsentState.ALLOWED,
ConsentState.DENIED
)
).size
},
2
)
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ class GroupPermissionsTest {
updateGroupDescriptionPolicy = PermissionOption.Allow,
updateGroupImagePolicy = PermissionOption.Admin,
updateGroupPinnedFrameUrlPolicy = PermissionOption.Deny,
updateMessageExpirationPolicy = PermissionOption.Admin,
)
val boGroup = runBlocking {
boClient.conversations.newGroupCustomPermissions(
Expand Down Expand Up @@ -468,6 +469,7 @@ class GroupPermissionsTest {
updateGroupDescriptionPolicy = PermissionOption.Allow,
updateGroupImagePolicy = PermissionOption.Admin,
updateGroupPinnedFrameUrlPolicy = PermissionOption.Deny,
updateMessageExpirationPolicy = PermissionOption.Admin,
)

assertThrows(GenericException.GroupMutablePermissions::class.java) {
Expand All @@ -488,6 +490,7 @@ class GroupPermissionsTest {
updateGroupDescriptionPolicy = PermissionOption.Allow,
updateGroupImagePolicy = PermissionOption.Admin,
updateGroupPinnedFrameUrlPolicy = PermissionOption.Deny,
updateMessageExpirationPolicy = PermissionOption.Allow,
)

// Valid custom policy works as expected
Expand All @@ -503,4 +506,38 @@ class GroupPermissionsTest {
runBlocking { alixClient.conversations.sync() }
assert(runBlocking { alixClient.conversations.listGroups() }.size == 1)
}

@Test
fun canCreateGroupWithInboxIdCustomPermissions() {
val permissionPolicySet = PermissionPolicySet(
addMemberPolicy = PermissionOption.Admin,
removeMemberPolicy = PermissionOption.Deny,
addAdminPolicy = PermissionOption.Admin,
removeAdminPolicy = PermissionOption.SuperAdmin,
updateGroupNamePolicy = PermissionOption.Admin,
updateGroupDescriptionPolicy = PermissionOption.Allow,
updateGroupImagePolicy = PermissionOption.Admin,
updateGroupPinnedFrameUrlPolicy = PermissionOption.Deny,
updateMessageExpirationPolicy = PermissionOption.Admin,
)
val boGroup = runBlocking {
boClient.conversations.newGroupCustomPermissionsWithInboxIds(
inboxIds = listOf(alixClient.inboxId, caroClient.inboxId),
permissionPolicySet = permissionPolicySet,
)
}
runBlocking { alixClient.conversations.sync() }
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }

// Verify permission look correct
val alixPermissionSet = alixGroup.permissionPolicySet()
assert(alixPermissionSet.addMemberPolicy == PermissionOption.Admin)
assert(alixPermissionSet.removeMemberPolicy == PermissionOption.Deny)
assert(alixPermissionSet.addAdminPolicy == PermissionOption.Admin)
assert(alixPermissionSet.removeAdminPolicy == PermissionOption.SuperAdmin)
assert(alixPermissionSet.updateGroupNamePolicy == PermissionOption.Admin)
assert(alixPermissionSet.updateGroupDescriptionPolicy == PermissionOption.Allow)
assert(alixPermissionSet.updateGroupImagePolicy == PermissionOption.Admin)
assert(alixPermissionSet.updateGroupPinnedFrameUrlPolicy == PermissionOption.Deny)
}
}
57 changes: 54 additions & 3 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,46 @@ class GroupTest {
assert(!runBlocking { alixGroup.isCreator() })
}

@Test
fun testCanCreateAGroupWithInboxIdsDefaultPermissions() {
val boGroup = runBlocking {
boClient.conversations.newGroupWithInboxIds(listOf(alixClient.inboxId))
}
runBlocking {
alixClient.conversations.sync()
boGroup.sync()
}
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }
assert(boGroup.id.isNotEmpty())
assert(alixGroup.id.isNotEmpty())

runBlocking {
alixGroup.addMembers(listOf(caro.walletAddress))
boGroup.sync()
}
assertEquals(runBlocking { alixGroup.members().size }, 3)
assertEquals(runBlocking { boGroup.members().size }, 3)

// All members also defaults remove to admin only now.
assertThrows(XMTPException::class.java) {
runBlocking {
alixGroup.removeMembers(listOf(caro.walletAddress))
boGroup.sync()
}
}

assertEquals(runBlocking { alixGroup.members().size }, 3)
assertEquals(runBlocking { boGroup.members().size }, 3)

assertEquals(boGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow)
assertEquals(alixGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow)
assertEquals(boGroup.isSuperAdmin(boClient.inboxId), true)
assertEquals(boGroup.isSuperAdmin(alixClient.inboxId), false)
assertEquals(alixGroup.isSuperAdmin(boClient.inboxId), true)
assertEquals(alixGroup.isSuperAdmin(alixClient.inboxId), false)
assert(!runBlocking { alixGroup.isCreator() })
}

@Test
fun testCanListGroupMembers() {
val group = runBlocking {
Expand Down Expand Up @@ -488,18 +528,29 @@ class GroupTest {
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
assertEquals(runBlocking { boClient.conversations.listGroups().size }, 2)
assertEquals(
runBlocking { boClient.conversations.listGroups(consentState = ConsentState.ALLOWED).size },
runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.ALLOWED)).size },
2
)
runBlocking { group.updateConsentState(ConsentState.DENIED) }
assertEquals(
runBlocking { boClient.conversations.listGroups(consentState = ConsentState.ALLOWED).size },
runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.ALLOWED)).size },
1
)
assertEquals(
runBlocking { boClient.conversations.listGroups(consentState = ConsentState.DENIED).size },
runBlocking { boClient.conversations.listGroups(consentStates = listOf(ConsentState.DENIED)).size },
1
)
assertEquals(
runBlocking {
boClient.conversations.listGroups(
consentStates = listOf(
ConsentState.ALLOWED,
ConsentState.DENIED
)
).size
},
2
)
assertEquals(runBlocking { boClient.conversations.listGroups().size }, 2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,31 @@ class ReadReceiptTest {
Client.register(codec = ReadReceiptCodec())

val fixtures = fixtures()
val aliceClient = fixtures.alixClient
val aliceConversation = runBlocking {
aliceClient.conversations.newConversation(fixtures.bo.walletAddress)
val alixClient = fixtures.alixClient
val alixConversation = runBlocking {
alixClient.conversations.newConversation(fixtures.bo.walletAddress)
}

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

val readReceipt = ReadReceipt

runBlocking {
aliceConversation.send(
alixConversation.send(
content = readReceipt,
options = SendOptions(contentType = ContentTypeReadReceipt),
)
}
val messages = runBlocking { aliceConversation.messages() }
val messages = runBlocking { alixConversation.messages() }
assertEquals(messages.size, 2)
if (messages.size == 2) {
val contentType: String = messages.first().encodedContent.type.typeId
assertEquals(contentType, "readReceipt")
}
val convos = runBlocking { alixClient.conversations.list() }
assertEquals(
runBlocking { convos.first().lastMessage() }!!.encodedContent.type.typeId,
"text"
)
}
}
11 changes: 2 additions & 9 deletions library/src/main/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ Kotlin code emitted by the `bindings_ffi` crate in [libxmtp](https://github.com/

## Process for updating from a [libxmtp](https://github.com/xmtp/libxmtp) Kotlin Binding Release

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
2. Create a new branch in the `xmtp-android` repo
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:
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)
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:
`./gen_kotlin.sh` within the `bindings_ffi` folder.
3. Run format (cmd + opt + l) function to keep the code format consistent and diff small for `xmtp-android/library/src/main/java/xmtpv3.kt`
4. Navigate to the [latest release](https://github.com/xmtp/libxmtp/releases) once the action completes
5. Download the `LibXMTPKotlinFFI.zip` assets
6. Unzip and then copy the jniLibs to `xmtp-android/library/src/main/jniLibs`
7. All instances of `value.forEach` should be changed to `value.iterator().forEach` to be compatible with API 23
8. NOTE: sometimes the library name gets updated and will cause failures the library name must be `uniffi_xmtpv3` not `xmtpv3` -- search for `findLibraryName` and make sure the correct name is returned.

You should now be on the latest libxmtp. Tests will fail if the jniLibs do not match the version of xmtpv3.
4 changes: 2 additions & 2 deletions library/src/main/java/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 76983ce7
Version: aaa58c22
Branch: cv/01-10-json_deserialization_for_legacy_reactions
Date: 2025-01-11 00:19:35 +0000
Date: 2025-01-17 23:20:35 +0000
Loading

0 comments on commit e6375f6

Please sign in to comment.