Skip to content

Commit be8c3bc

Browse files
authored
Add isActive to Groups (#176)
* update to latest v3 version * add is active check to groups * surface version for debugging * update the so files to match * fix up the is active test * fix up some unneeded imports * remove the syncing * update log
1 parent fd50405 commit be8c3bc

File tree

8 files changed

+80
-7
lines changed

8 files changed

+80
-7
lines changed

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

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.xmtp.android.library
33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import androidx.test.platform.app.InstrumentationRegistry
55
import app.cash.turbine.test
6-
import kotlinx.coroutines.ExperimentalCoroutinesApi
76
import kotlinx.coroutines.runBlocking
87
import org.junit.Assert.assertEquals
98
import org.junit.Assert.assertThrows
@@ -113,6 +112,25 @@ class GroupTest {
113112
)
114113
}
115114

115+
@Test
116+
fun testIsActiveReturnsCorrectly() {
117+
val group = boClient.conversations.newGroup(
118+
listOf(
119+
alix.walletAddress,
120+
caro.walletAddress
121+
)
122+
)
123+
runBlocking { caroClient.conversations.syncGroups() }
124+
val caroGroup = caroClient.conversations.listGroups().first()
125+
runBlocking { caroGroup.sync() }
126+
assert(caroGroup.isActive())
127+
assert(group.isActive())
128+
group.removeMembers(listOf(caro.walletAddress))
129+
runBlocking { caroGroup.sync() }
130+
assert(group.isActive())
131+
assert(!caroGroup.isActive())
132+
}
133+
116134
@Test
117135
fun testCanListGroups() {
118136
boClient.conversations.newGroup(listOf(alix.walletAddress))
@@ -200,11 +218,9 @@ class GroupTest {
200218
assertEquals(ReactionSchema.Unicode, content?.schema)
201219
}
202220

203-
@OptIn(ExperimentalCoroutinesApi::class)
204221
@Test
205222
fun testCanStreamGroupMessages() = kotlinx.coroutines.test.runTest {
206223
val group = boClient.conversations.newGroup(listOf(alix.walletAddress.lowercase()))
207-
208224
group.streamMessages().test {
209225
group.send("hi")
210226
assertEquals("hi", awaitItem().body)
@@ -213,7 +229,6 @@ class GroupTest {
213229
}
214230
}
215231

216-
@OptIn(ExperimentalCoroutinesApi::class)
217232
@Test
218233
fun testCanStreamDecryptedGroupMessages() = kotlinx.coroutines.test.runTest {
219234
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
@@ -226,7 +241,6 @@ class GroupTest {
226241
}
227242
}
228243

229-
@OptIn(ExperimentalCoroutinesApi::class)
230244
@Test
231245
fun testCanStreamGroups() = kotlinx.coroutines.test.runTest {
232246
boClient.conversations.streamGroups().test {
@@ -239,7 +253,6 @@ class GroupTest {
239253
}
240254
}
241255

242-
@OptIn(ExperimentalCoroutinesApi::class)
243256
@Test
244257
fun testCanStreamGroupsAndConversations() = kotlinx.coroutines.test.runTest {
245258
boClient.conversations.streamAll().test {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
4444
import uniffi.xmtpv3.FfiXmtpClient
4545
import uniffi.xmtpv3.LegacyIdentitySource
4646
import uniffi.xmtpv3.createClient
47+
import uniffi.xmtpv3.getVersionInfo
4748
import java.io.File
4849
import java.nio.charset.StandardCharsets
4950
import java.security.KeyStore
@@ -81,6 +82,7 @@ class Client() {
8182
lateinit var conversations: Conversations
8283
var logger: XMTPLogger = XMTPLogger()
8384
var libXMTPClient: FfiXmtpClient? = null
85+
val libXMTPVersion: String = getVersionInfo()
8486

8587
companion object {
8688
private const val TAG = "Client"
@@ -347,7 +349,7 @@ class Client() {
347349
throw XMTPException("No signer passed but signer was required.")
348350
}
349351
}
350-
352+
Log.i(TAG, "LibXMTP $libXMTPVersion")
351353
return v3Client
352354
}
353355

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

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
128128
)
129129
}
130130

131+
fun isActive(): Boolean {
132+
return libXMTPGroup.isActive()
133+
}
134+
131135
fun addMembers(addresses: List<String>) {
132136
runBlocking { libXMTPGroup.addMembers(addresses) }
133137
}

library/src/main/java/xmtpv3.kt

+54
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ internal interface _UniFFILib : Library {
413413
): RustBuffer.ByValue
414414
fun uniffi_xmtpv3_fn_method_ffigroup_id(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
415415
): RustBuffer.ByValue
416+
fun uniffi_xmtpv3_fn_method_ffigroup_is_active(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
417+
): Byte
416418
fun uniffi_xmtpv3_fn_method_ffigroup_list_members(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
417419
): RustBuffer.ByValue
418420
fun uniffi_xmtpv3_fn_method_ffigroup_remove_members(`ptr`: Pointer,`accountAddresses`: RustBuffer.ByValue,
@@ -427,6 +429,8 @@ internal interface _UniFFILib : Library {
427429
): Unit
428430
fun uniffi_xmtpv3_fn_method_ffistreamcloser_end(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
429431
): Unit
432+
fun uniffi_xmtpv3_fn_method_ffistreamcloser_is_closed(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
433+
): Byte
430434
fun uniffi_xmtpv3_fn_free_ffiv2apiclient(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
431435
): Unit
432436
fun uniffi_xmtpv3_fn_method_ffiv2apiclient_batch_query(`ptr`: Pointer,`req`: RustBuffer.ByValue,
@@ -475,6 +479,8 @@ internal interface _UniFFILib : Library {
475479
): RustBuffer.ByValue
476480
fun uniffi_xmtpv3_fn_func_generate_private_preferences_topic_identifier(`privateKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
477481
): RustBuffer.ByValue
482+
fun uniffi_xmtpv3_fn_func_get_version_info(_uniffi_out_err: RustCallStatus,
483+
): RustBuffer.ByValue
478484
fun uniffi_xmtpv3_fn_func_keccak256(`input`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
479485
): RustBuffer.ByValue
480486
fun uniffi_xmtpv3_fn_func_public_key_from_private_key_k256(`privateKeyBytes`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
@@ -615,6 +621,8 @@ internal interface _UniFFILib : Library {
615621
): Short
616622
fun uniffi_xmtpv3_checksum_func_generate_private_preferences_topic_identifier(
617623
): Short
624+
fun uniffi_xmtpv3_checksum_func_get_version_info(
625+
): Short
618626
fun uniffi_xmtpv3_checksum_func_keccak256(
619627
): Short
620628
fun uniffi_xmtpv3_checksum_func_public_key_from_private_key_k256(
@@ -649,6 +657,8 @@ internal interface _UniFFILib : Library {
649657
): Short
650658
fun uniffi_xmtpv3_checksum_method_ffigroup_id(
651659
): Short
660+
fun uniffi_xmtpv3_checksum_method_ffigroup_is_active(
661+
): Short
652662
fun uniffi_xmtpv3_checksum_method_ffigroup_list_members(
653663
): Short
654664
fun uniffi_xmtpv3_checksum_method_ffigroup_remove_members(
@@ -661,6 +671,8 @@ internal interface _UniFFILib : Library {
661671
): Short
662672
fun uniffi_xmtpv3_checksum_method_ffistreamcloser_end(
663673
): Short
674+
fun uniffi_xmtpv3_checksum_method_ffistreamcloser_is_closed(
675+
): Short
664676
fun uniffi_xmtpv3_checksum_method_ffiv2apiclient_batch_query(
665677
): Short
666678
fun uniffi_xmtpv3_checksum_method_ffiv2apiclient_publish(
@@ -726,6 +738,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
726738
if (lib.uniffi_xmtpv3_checksum_func_generate_private_preferences_topic_identifier() != 5952.toShort()) {
727739
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
728740
}
741+
if (lib.uniffi_xmtpv3_checksum_func_get_version_info() != 3533.toShort()) {
742+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
743+
}
729744
if (lib.uniffi_xmtpv3_checksum_func_keccak256() != 17749.toShort()) {
730745
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
731746
}
@@ -777,6 +792,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
777792
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_id() != 35243.toShort()) {
778793
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
779794
}
795+
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_is_active() != 27808.toShort()) {
796+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
797+
}
780798
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_list_members() != 15786.toShort()) {
781799
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
782800
}
@@ -795,6 +813,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
795813
if (lib.uniffi_xmtpv3_checksum_method_ffistreamcloser_end() != 47211.toShort()) {
796814
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
797815
}
816+
if (lib.uniffi_xmtpv3_checksum_method_ffistreamcloser_is_closed() != 37884.toShort()) {
817+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
818+
}
798819
if (lib.uniffi_xmtpv3_checksum_method_ffiv2apiclient_batch_query() != 10812.toShort()) {
799820
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
800821
}
@@ -1379,6 +1400,7 @@ public interface FfiGroupInterface {
13791400
fun `createdAtNs`(): Long@Throws(GenericException::class)
13801401
fun `findMessages`(`opts`: FfiListMessagesOptions): List<FfiMessage>
13811402
fun `id`(): ByteArray@Throws(GenericException::class)
1403+
fun `isActive`(): Boolean@Throws(GenericException::class)
13821404
fun `listMembers`(): List<FfiGroupMember>@Throws(GenericException::class)
13831405
suspend fun `removeMembers`(`accountAddresses`: List<String>)@Throws(GenericException::class)
13841406
suspend fun `send`(`contentBytes`: ByteArray)@Throws(GenericException::class)
@@ -1461,6 +1483,18 @@ class FfiGroup(
14611483
}
14621484

14631485

1486+
@Throws(GenericException::class)override fun `isActive`(): Boolean =
1487+
callWithPointer {
1488+
rustCallWithError(GenericException) { _status ->
1489+
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroup_is_active(it,
1490+
1491+
_status)
1492+
}
1493+
}.let {
1494+
FfiConverterBoolean.lift(it)
1495+
}
1496+
1497+
14641498
@Throws(GenericException::class)override fun `listMembers`(): List<FfiGroupMember> =
14651499
callWithPointer {
14661500
rustCallWithError(GenericException) { _status ->
@@ -1590,6 +1624,7 @@ public object FfiConverterTypeFfiGroup: FfiConverter<FfiGroup, Pointer> {
15901624
public interface FfiStreamCloserInterface {
15911625

15921626
fun `end`()
1627+
fun `isClosed`(): Boolean
15931628
companion object
15941629
}
15951630

@@ -1621,6 +1656,17 @@ class FfiStreamCloser(
16211656
}
16221657

16231658

1659+
override fun `isClosed`(): Boolean =
1660+
callWithPointer {
1661+
rustCall() { _status ->
1662+
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffistreamcloser_is_closed(it,
1663+
1664+
_status)
1665+
}
1666+
}.let {
1667+
FfiConverterBoolean.lift(it)
1668+
}
1669+
16241670

16251671

16261672

@@ -3511,6 +3557,14 @@ fun `generatePrivatePreferencesTopicIdentifier`(`privateKey`: ByteArray): String
35113557
}
35123558

35133559

3560+
fun `getVersionInfo`(): String {
3561+
return FfiConverterString.lift(
3562+
rustCall() { _status ->
3563+
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_func_get_version_info(_status)
3564+
})
3565+
}
3566+
3567+
35143568
fun `keccak256`(`input`: ByteArray): ByteArray {
35153569
return FfiConverterByteArray.lift(
35163570
rustCall() { _status ->
Binary file not shown.
Binary file not shown.
-305 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)