Skip to content

Commit e7fcfaa

Browse files
committed
add group name functions
1 parent 3d33a40 commit e7fcfaa

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ class GroupTest {
177177
)
178178
}
179179

180+
@Test
181+
fun testNameAGroup() {
182+
val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) }
183+
runBlocking {
184+
assertEquals("New Group", boGroup.name)
185+
boGroup.updateGroupName("This Is A Great Group")
186+
boGroup.sync()
187+
alixClient.conversations.syncGroups()
188+
}
189+
val alixGroup = runBlocking { alixClient.conversations.listGroups().first() }
190+
runBlocking { alixGroup.sync() }
191+
assertEquals("This Is A Great Group", boGroup.name)
192+
assertEquals("This Is A Great Group", alixGroup.name)
193+
}
194+
180195
@Test
181196
fun testCanAddGroupMembers() {
182197
val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) }

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

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
3434
private val metadata: FfiGroupMetadata
3535
get() = libXMTPGroup.groupMetadata()
3636

37+
val name: String
38+
get() = libXMTPGroup.groupName()
39+
3740
suspend fun send(text: String): String {
3841
return send(prepareMessage(content = text, options = null))
3942
}
@@ -172,6 +175,10 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
172175
return addresses
173176
}
174177

178+
suspend fun updateGroupName(name: String) {
179+
return libXMTPGroup.updateGroupName(name)
180+
}
181+
175182
fun streamMessages(): Flow<DecodedMessage> = callbackFlow {
176183
val messageCallback = object : FfiMessageCallback {
177184
override fun onMessage(message: FfiMessage) {

library/src/main/java/xmtpv3.kt

+51-2
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ internal interface _UniFFILib : Library {
417417
): RustBuffer.ByValue
418418
fun uniffi_xmtpv3_fn_method_ffigroup_group_metadata(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
419419
): Pointer
420+
fun uniffi_xmtpv3_fn_method_ffigroup_group_name(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
421+
): RustBuffer.ByValue
420422
fun uniffi_xmtpv3_fn_method_ffigroup_id(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
421423
): RustBuffer.ByValue
422424
fun uniffi_xmtpv3_fn_method_ffigroup_is_active(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
@@ -433,6 +435,8 @@ internal interface _UniFFILib : Library {
433435
): Pointer
434436
fun uniffi_xmtpv3_fn_method_ffigroup_sync(`ptr`: Pointer,
435437
): Pointer
438+
fun uniffi_xmtpv3_fn_method_ffigroup_update_group_name(`ptr`: Pointer,`groupName`: RustBuffer.ByValue,
439+
): Pointer
436440
fun uniffi_xmtpv3_fn_free_ffigroupmetadata(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
437441
): Unit
438442
fun uniffi_xmtpv3_fn_method_ffigroupmetadata_conversation_type(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
@@ -679,6 +683,8 @@ internal interface _UniFFILib : Library {
679683
): Short
680684
fun uniffi_xmtpv3_checksum_method_ffigroup_group_metadata(
681685
): Short
686+
fun uniffi_xmtpv3_checksum_method_ffigroup_group_name(
687+
): Short
682688
fun uniffi_xmtpv3_checksum_method_ffigroup_id(
683689
): Short
684690
fun uniffi_xmtpv3_checksum_method_ffigroup_is_active(
@@ -695,6 +701,8 @@ internal interface _UniFFILib : Library {
695701
): Short
696702
fun uniffi_xmtpv3_checksum_method_ffigroup_sync(
697703
): Short
704+
fun uniffi_xmtpv3_checksum_method_ffigroup_update_group_name(
705+
): Short
698706
fun uniffi_xmtpv3_checksum_method_ffigroupmetadata_conversation_type(
699707
): Short
700708
fun uniffi_xmtpv3_checksum_method_ffigroupmetadata_creator_account_address(
@@ -832,6 +840,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
832840
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_group_metadata() != 3690.toShort()) {
833841
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
834842
}
843+
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_group_name() != 3391.toShort()) {
844+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
845+
}
835846
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_id() != 35243.toShort()) {
836847
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
837848
}
@@ -856,6 +867,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
856867
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_sync() != 9422.toShort()) {
857868
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
858869
}
870+
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_update_group_name() != 29940.toShort()) {
871+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
872+
}
859873
if (lib.uniffi_xmtpv3_checksum_method_ffigroupmetadata_conversation_type() != 37015.toShort()) {
860874
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
861875
}
@@ -1491,15 +1505,17 @@ public interface FfiGroupInterface {
14911505
suspend fun `addMembers`(`accountAddresses`: List<String>)
14921506
fun `createdAtNs`(): Long@Throws(GenericException::class)
14931507
fun `findMessages`(`opts`: FfiListMessagesOptions): List<FfiMessage>@Throws(GenericException::class)
1494-
fun `groupMetadata`(): FfiGroupMetadata
1508+
fun `groupMetadata`(): FfiGroupMetadata@Throws(GenericException::class)
1509+
fun `groupName`(): String
14951510
fun `id`(): ByteArray@Throws(GenericException::class)
14961511
fun `isActive`(): Boolean@Throws(GenericException::class)
14971512
fun `listMembers`(): List<FfiGroupMember>@Throws(GenericException::class)
14981513
suspend fun `processStreamedGroupMessage`(`envelopeBytes`: ByteArray): FfiMessage@Throws(GenericException::class)
14991514
suspend fun `removeMembers`(`accountAddresses`: List<String>)@Throws(GenericException::class)
15001515
suspend fun `send`(`contentBytes`: ByteArray)@Throws(GenericException::class)
15011516
suspend fun `stream`(`messageCallback`: FfiMessageCallback): FfiStreamCloser@Throws(GenericException::class)
1502-
suspend fun `sync`()
1517+
suspend fun `sync`()@Throws(GenericException::class)
1518+
suspend fun `updateGroupName`(`groupName`: String)
15031519
companion object
15041520
}
15051521

@@ -1577,6 +1593,18 @@ class FfiGroup(
15771593
FfiConverterTypeFfiGroupMetadata.lift(it)
15781594
}
15791595

1596+
1597+
@Throws(GenericException::class)override fun `groupName`(): String =
1598+
callWithPointer {
1599+
rustCallWithError(GenericException) { _status ->
1600+
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroup_group_name(it,
1601+
1602+
_status)
1603+
}
1604+
}.let {
1605+
FfiConverterString.lift(it)
1606+
}
1607+
15801608
override fun `id`(): ByteArray =
15811609
callWithPointer {
15821610
rustCall() { _status ->
@@ -1716,6 +1744,27 @@ class FfiGroup(
17161744
)
17171745
}
17181746

1747+
@Throws(GenericException::class)
1748+
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
1749+
override suspend fun `updateGroupName`(`groupName`: String) {
1750+
return uniffiRustCallAsync(
1751+
callWithPointer { thisPtr ->
1752+
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroup_update_group_name(
1753+
thisPtr,
1754+
FfiConverterString.lower(`groupName`),
1755+
)
1756+
},
1757+
{ future, continuation -> _UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_poll_void(future, continuation) },
1758+
{ future, continuation -> _UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_complete_void(future, continuation) },
1759+
{ future -> _UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_free_void(future) },
1760+
// lift function
1761+
{ Unit },
1762+
1763+
// Error FFI converter
1764+
GenericException.ErrorHandler,
1765+
)
1766+
}
1767+
17191768

17201769

17211770
companion object

0 commit comments

Comments
 (0)