Skip to content

Commit

Permalink
Add group image url (#255)
Browse files Browse the repository at this point in the history
* bump the package

* update the bindings

* add the image url fields

* add a test for it

* fix lint
  • Loading branch information
nplasterer authored Jun 13, 2024
1 parent 71d9df5 commit fb443cc
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 18 deletions.
16 changes: 13 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 @@ -207,18 +207,28 @@ class GroupTest {
}

@Test
fun testNameAGroup() {
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) }
fun testGroupMetadata() {
val boGroup = runBlocking {
boClient.conversations.newGroup(
listOf(alix.walletAddress),
groupName = "Starting Name",
groupImageUrlSquare = "startingurl.com"
)
}
runBlocking {
assertEquals("", boGroup.name)
assertEquals("Starting Name", boGroup.name)
assertEquals("startingurl.com", boGroup.imageUrlSquare)
boGroup.updateGroupName("This Is A Great Group")
boGroup.updateGroupImageUrlSquare("thisisanewurl.com")
boGroup.sync()
alixClient.conversations.syncGroups()
}
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }
runBlocking { alixGroup.sync() }
assertEquals("This Is A Great Group", boGroup.name)
assertEquals("This Is A Great Group", alixGroup.name)
assertEquals("thisisanewurl.com", boGroup.imageUrlSquare)
assertEquals("thisisanewurl.com", alixGroup.imageUrlSquare)
}

@Test
Expand Down
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: 46fad302
Version: 6d880763
Branch: main
Date: 2024-06-04 02:30:29 +0000
Date: 2024-06-13 06:20:50 +0000
13 changes: 11 additions & 2 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.xmtp.proto.message.contents.Contact
import org.xmtp.proto.message.contents.Invitation
import uniffi.xmtpv3.FfiConversationCallback
import uniffi.xmtpv3.FfiConversations
import uniffi.xmtpv3.FfiCreateGroupOptions
import uniffi.xmtpv3.FfiGroup
import uniffi.xmtpv3.FfiListConversationsOptions
import uniffi.xmtpv3.FfiMessage
Expand Down Expand Up @@ -107,6 +108,8 @@ data class Conversations(
suspend fun newGroup(
accountAddresses: List<String>,
permissions: GroupPermissions = GroupPermissions.ALL_MEMBERS,
groupName: String = "",
groupImageUrlSquare: String = "",
): Group {
if (accountAddresses.size == 1 &&
accountAddresses.first().lowercase() == client.address.lowercase()
Expand All @@ -121,8 +124,14 @@ data class Conversations(
}

val group =
libXMTPConversations?.createGroup(accountAddresses, permissions = permissions)
?: throw XMTPException("Client does not support Groups")
libXMTPConversations?.createGroup(
accountAddresses,
opts = FfiCreateGroupOptions(
permissions = permissions,
groupName = groupName,
groupImageUrlSquare = groupImageUrlSquare
)
) ?: throw XMTPException("Client does not support Groups")
client.contacts.allowGroups(groupIds = listOf(group.id()))

return Group(client, group)
Expand Down
7 changes: 7 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 @@ -44,6 +44,9 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
val name: String
get() = libXMTPGroup.groupName()

val imageUrlSquare: String
get() = libXMTPGroup.groupImageUrlSquare()

suspend fun send(text: String): String {
return send(prepareMessage(content = text, options = null))
}
Expand Down Expand Up @@ -220,6 +223,10 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
return libXMTPGroup.updateGroupName(name)
}

suspend fun updateGroupImageUrlSquare(imageUrl: String) {
return libXMTPGroup.updateGroupImageUrlSquare(imageUrl)
}

fun isAdmin(inboxId: String): Boolean {
return libXMTPGroup.isAdmin(inboxId)
}
Expand Down
126 changes: 115 additions & 11 deletions library/src/main/java/xmtpv3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ internal interface UniffiLib : Library {
): Unit

fun uniffi_xmtpv3_fn_method_fficonversations_create_group(
`ptr`: Pointer, `accountAddresses`: RustBuffer.ByValue, `permissions`: RustBuffer.ByValue,
`ptr`: Pointer, `accountAddresses`: RustBuffer.ByValue, `opts`: RustBuffer.ByValue,
): Long

fun uniffi_xmtpv3_fn_method_fficonversations_list(
Expand Down Expand Up @@ -904,6 +904,10 @@ internal interface UniffiLib : Library {
`ptr`: Pointer, `opts`: RustBuffer.ByValue, uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue

fun uniffi_xmtpv3_fn_method_ffigroup_group_image_url_square(
`ptr`: Pointer, uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue

fun uniffi_xmtpv3_fn_method_ffigroup_group_metadata(
`ptr`: Pointer, uniffi_out_err: UniffiRustCallStatus,
): Pointer
Expand Down Expand Up @@ -972,6 +976,10 @@ internal interface UniffiLib : Library {
`ptr`: Pointer,
): Long

fun uniffi_xmtpv3_fn_method_ffigroup_update_group_image_url_square(
`ptr`: Pointer, `groupImageUrlSquare`: RustBuffer.ByValue,
): Long

fun uniffi_xmtpv3_fn_method_ffigroup_update_group_name(
`ptr`: Pointer, `groupName`: RustBuffer.ByValue,
): Long
Expand Down Expand Up @@ -1016,7 +1024,7 @@ internal interface UniffiLib : Library {
`ptr`: Pointer, `signatureBytes`: RustBuffer.ByValue,
): Long

fun uniffi_xmtpv3_fn_method_ffisignaturerequest_add_erc1271_signature(
fun uniffi_xmtpv3_fn_method_ffisignaturerequest_add_scw_signature(
`ptr`: Pointer,
`signatureBytes`: RustBuffer.ByValue,
`address`: RustBuffer.ByValue,
Expand Down Expand Up @@ -1562,6 +1570,9 @@ internal interface UniffiLib : Library {
fun uniffi_xmtpv3_checksum_method_ffigroup_find_messages(
): Short

fun uniffi_xmtpv3_checksum_method_ffigroup_group_image_url_square(
): Short

fun uniffi_xmtpv3_checksum_method_ffigroup_group_metadata(
): Short

Expand Down Expand Up @@ -1613,6 +1624,9 @@ internal interface UniffiLib : Library {
fun uniffi_xmtpv3_checksum_method_ffigroup_sync(
): Short

fun uniffi_xmtpv3_checksum_method_ffigroup_update_group_image_url_square(
): Short

fun uniffi_xmtpv3_checksum_method_ffigroup_update_group_name(
): Short

Expand All @@ -1628,7 +1642,7 @@ internal interface UniffiLib : Library {
fun uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_ecdsa_signature(
): Short

fun uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_erc1271_signature(
fun uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_scw_signature(
): Short

fun uniffi_xmtpv3_checksum_method_ffisignaturerequest_is_ready(
Expand Down Expand Up @@ -1774,7 +1788,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_xmtpv3_checksum_func_verify_k256_sha256() != 25521.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 1475.toShort()) {
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 62996.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_list() != 10804.toShort()) {
Expand Down Expand Up @@ -1816,6 +1830,9 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_find_messages() != 14930.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_group_image_url_square() != 16754.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_group_metadata() != 13139.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -1867,6 +1884,9 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_sync() != 24219.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_update_group_image_url_square() != 18878.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_update_group_name() != 550.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand All @@ -1882,7 +1902,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_ecdsa_signature() != 8706.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_erc1271_signature() != 27040.toShort()) {
if (lib.uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_scw_signature() != 59425.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffisignaturerequest_is_ready() != 65051.toShort()) {
Expand Down Expand Up @@ -2379,7 +2399,7 @@ public interface FfiConversationsInterface {

suspend fun `createGroup`(
`accountAddresses`: List<kotlin.String>,
`permissions`: GroupPermissions?,
`opts`: FfiCreateGroupOptions,
): FfiGroup

suspend fun `list`(`opts`: FfiListConversationsOptions): List<FfiGroup>
Expand Down Expand Up @@ -2481,14 +2501,14 @@ open class FfiConversations : Disposable, AutoCloseable, FfiConversationsInterfa
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `createGroup`(
`accountAddresses`: List<kotlin.String>,
`permissions`: GroupPermissions?,
`opts`: FfiCreateGroupOptions,
): FfiGroup {
return uniffiRustCallAsync(
callWithPointer { thisPtr ->
UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_fficonversations_create_group(
thisPtr,
FfiConverterSequenceString.lower(`accountAddresses`),
FfiConverterOptionalTypeGroupPermissions.lower(`permissions`),
FfiConverterTypeFfiCreateGroupOptions.lower(`opts`),
)
},
{ future, callback, continuation ->
Expand Down Expand Up @@ -2820,6 +2840,8 @@ public interface FfiGroupInterface {

fun `findMessages`(`opts`: FfiListMessagesOptions): List<FfiMessage>

fun `groupImageUrlSquare`(): kotlin.String

fun `groupMetadata`(): FfiGroupMetadata

fun `groupName`(): kotlin.String
Expand Down Expand Up @@ -2854,6 +2876,8 @@ public interface FfiGroupInterface {

suspend fun `sync`()

suspend fun `updateGroupImageUrlSquare`(`groupImageUrlSquare`: kotlin.String)

suspend fun `updateGroupName`(`groupName`: kotlin.String)

companion object
Expand Down Expand Up @@ -3128,6 +3152,20 @@ open class FfiGroup : Disposable, AutoCloseable, FfiGroupInterface {
}


@Throws(GenericException::class)
override fun `groupImageUrlSquare`(): kotlin.String {
return FfiConverterString.lift(
callWithPointer {
uniffiRustCallWithError(GenericException) { _status ->
UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroup_group_image_url_square(
it, _status
)
}
}
)
}


@Throws(GenericException::class)
override fun `groupMetadata`(): FfiGroupMetadata {
return FfiConverterTypeFfiGroupMetadata.lift(
Expand Down Expand Up @@ -3514,6 +3552,39 @@ open class FfiGroup : Disposable, AutoCloseable, FfiGroupInterface {
}


@Throws(GenericException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `updateGroupImageUrlSquare`(`groupImageUrlSquare`: kotlin.String) {
return uniffiRustCallAsync(
callWithPointer { thisPtr ->
UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroup_update_group_image_url_square(
thisPtr,
FfiConverterString.lower(`groupImageUrlSquare`),
)
},
{ future, callback, continuation ->
UniffiLib.INSTANCE.ffi_xmtpv3_rust_future_poll_void(
future,
callback,
continuation
)
},
{ future, continuation ->
UniffiLib.INSTANCE.ffi_xmtpv3_rust_future_complete_void(
future,
continuation
)
},
{ future -> UniffiLib.INSTANCE.ffi_xmtpv3_rust_future_free_void(future) },
// lift function
{ Unit },

// Error FFI converter
GenericException.ErrorHandler,
)
}


@Throws(GenericException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `updateGroupName`(`groupName`: kotlin.String) {
Expand Down Expand Up @@ -4154,7 +4225,7 @@ public interface FfiSignatureRequestInterface {

suspend fun `addEcdsaSignature`(`signatureBytes`: kotlin.ByteArray)

suspend fun `addErc1271Signature`(
suspend fun `addScwSignature`(
`signatureBytes`: kotlin.ByteArray,
`address`: kotlin.String,
`chainRpcUrl`: kotlin.String,
Expand Down Expand Up @@ -4289,14 +4360,14 @@ open class FfiSignatureRequest : Disposable, AutoCloseable, FfiSignatureRequestI

@Throws(GenericException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `addErc1271Signature`(
override suspend fun `addScwSignature`(
`signatureBytes`: kotlin.ByteArray,
`address`: kotlin.String,
`chainRpcUrl`: kotlin.String,
) {
return uniffiRustCallAsync(
callWithPointer { thisPtr ->
UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_ffisignaturerequest_add_erc1271_signature(
UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_ffisignaturerequest_add_scw_signature(
thisPtr,
FfiConverterByteArray.lower(`signatureBytes`),
FfiConverterString.lower(`address`),
Expand Down Expand Up @@ -5767,6 +5838,39 @@ public object FfiConverterTypeFfiXmtpClient : FfiConverter<FfiXmtpClient, Pointe
}


data class FfiCreateGroupOptions(
var `permissions`: GroupPermissions?,
var `groupName`: kotlin.String?,
var `groupImageUrlSquare`: kotlin.String?,
) {

companion object
}

public object FfiConverterTypeFfiCreateGroupOptions :
FfiConverterRustBuffer<FfiCreateGroupOptions> {
override fun read(buf: ByteBuffer): FfiCreateGroupOptions {
return FfiCreateGroupOptions(
FfiConverterOptionalTypeGroupPermissions.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
)
}

override fun allocationSize(value: FfiCreateGroupOptions) = (
FfiConverterOptionalTypeGroupPermissions.allocationSize(value.`permissions`) +
FfiConverterOptionalString.allocationSize(value.`groupName`) +
FfiConverterOptionalString.allocationSize(value.`groupImageUrlSquare`)
)

override fun write(value: FfiCreateGroupOptions, buf: ByteBuffer) {
FfiConverterOptionalTypeGroupPermissions.write(value.`permissions`, buf)
FfiConverterOptionalString.write(value.`groupName`, buf)
FfiConverterOptionalString.write(value.`groupImageUrlSquare`, buf)
}
}


data class FfiCursor(
var `digest`: kotlin.ByteArray,
var `senderTimeNs`: kotlin.ULong,
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 fb443cc

Please sign in to comment.