Skip to content

Commit

Permalink
Who Added Me Functionality (#230)
Browse files Browse the repository at this point in the history
* Update LibXMTP Kotlin README

* dump the xmtpv3 code

* bump all the jni libs

* added_by_address implementation + test

* Fix test with lowercase()

---------

Co-authored-by: Naomi Plasterer <[email protected]>
  • Loading branch information
zombieobject and nplasterer authored Apr 18, 2024
1 parent 7c336e7 commit 6030e8c
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
14 changes: 14 additions & 0 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ class GroupTest {
assert(!caroGroup.isActive())
}

@Test
fun testAddedByAddress() {
val group = runBlocking {
alixClient.conversations.newGroup(
listOf(
bo.walletAddress,
)
)
}
runBlocking { boClient.conversations.syncGroups() }
val boGroup = runBlocking { boClient.conversations.listGroups().first() }
assertEquals(boGroup.addedByAddress().lowercase(), alix.walletAddress.lowercase())
}

@Test
fun testCanListGroups() {
runBlocking {
Expand Down
9 changes: 4 additions & 5 deletions library/src/main/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ Kotlin code emitted by the `bindings_ffi` crate in [libxmtp](https://github.com/

1. From repo [libxmtp](https://github.com/xmtp/libxmtp) checkout the branch you would like to make a release from
2. Navigate to the `bindings_ffi` folder
3. Run `./gen_kotlin.sh`
4. Run `./cross_build.sh`
5. Copy the contents of `libxmtp/bindings_ffi/src/uniffi/xmtpv3/xmtpv3.kt` to `xmtp-android/library/src/main/java/xmtpv3.kt`
6. All instances of `value.forEach` should be changed to `value.iterator().forEach` to be compatible with API 23
7. Copy the jniLibs from `libxmtp/bindings_ffi/jniLibs` to `xmtp-android/library/src/main/jniLibs`
3. Follow the instructions for "Rebuilding this crate in the `bindings_ffi` [README](https://github.com/xmtp/libxmtp/tree/main/bindings_ffi#rebuilding-this-crate)"
4. Copy the contents of `libxmtp/bindings_ffi/src/uniffi/xmtpv3/xmtpv3.kt` to `xmtp-android/library/src/main/java/xmtpv3.kt`
5. All instances of `value.forEach` should be changed to `value.iterator().forEach` to be compatible with API 23
6. Copy the jniLibs from `libxmtp/bindings_ffi/jniLibs` to `xmtp-android/library/src/main/jniLibs`

You should now be on the latest libxmtp. Tests will fail if the jniLibs do not match the version of xmtpv3.
4 changes: 4 additions & 0 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
return libXMTPGroup.isActive()
}

fun addedByAddress(): String {
return libXMTPGroup.addedByAddress()
}

fun permissionLevel(): GroupPermissions {
return metadata.policyType()
}
Expand Down
22 changes: 21 additions & 1 deletion library/src/main/java/xmtpv3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ internal interface _UniFFILib : Library {
): Unit
fun uniffi_xmtpv3_fn_method_ffigroup_add_members(`ptr`: Pointer,`accountAddresses`: RustBuffer.ByValue,
): Pointer
fun uniffi_xmtpv3_fn_method_ffigroup_added_by_address(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_method_ffigroup_created_at_ns(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): Long
fun uniffi_xmtpv3_fn_method_ffigroup_find_messages(`ptr`: Pointer,`opts`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
Expand Down Expand Up @@ -673,6 +675,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_add_members(
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_added_by_address(
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_created_at_ns(
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_find_messages(
Expand Down Expand Up @@ -823,6 +827,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_add_members() != 24978.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_added_by_address() != 5368.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_created_at_ns() != 58515.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -1488,7 +1495,8 @@ public object FfiConverterTypeFfiConversations: FfiConverter<FfiConversations, P

public interface FfiGroupInterface {
@Throws(GenericException::class)
suspend fun `addMembers`(`accountAddresses`: List<String>)
suspend fun `addMembers`(`accountAddresses`: List<String>)@Throws(GenericException::class)
fun `addedByAddress`(): String
fun `createdAtNs`(): Long@Throws(GenericException::class)
fun `findMessages`(`opts`: FfiListMessagesOptions): List<FfiMessage>@Throws(GenericException::class)
fun `groupMetadata`(): FfiGroupMetadata
Expand Down Expand Up @@ -1542,6 +1550,18 @@ class FfiGroup(
GenericException.ErrorHandler,
)
}

@Throws(GenericException::class)override fun `addedByAddress`(): String =
callWithPointer {
rustCallWithError(GenericException) { _status ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroup_added_by_address(it,

_status)
}
}.let {
FfiConverterString.lift(it)
}

override fun `createdAtNs`(): Long =
callWithPointer {
rustCall() { _status ->
Expand Down
Binary file modified library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so
Binary file not shown.

0 comments on commit 6030e8c

Please sign in to comment.