Skip to content

Commit

Permalink
Add isActive to Groups (#176)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nplasterer authored Feb 13, 2024
1 parent fd50405 commit be8c3bc
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 7 deletions.
25 changes: 19 additions & 6 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.xmtp.android.library
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import app.cash.turbine.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
Expand Down Expand Up @@ -113,6 +112,25 @@ class GroupTest {
)
}

@Test
fun testIsActiveReturnsCorrectly() {
val group = boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
)
)
runBlocking { caroClient.conversations.syncGroups() }
val caroGroup = caroClient.conversations.listGroups().first()
runBlocking { caroGroup.sync() }
assert(caroGroup.isActive())
assert(group.isActive())
group.removeMembers(listOf(caro.walletAddress))
runBlocking { caroGroup.sync() }
assert(group.isActive())
assert(!caroGroup.isActive())
}

@Test
fun testCanListGroups() {
boClient.conversations.newGroup(listOf(alix.walletAddress))
Expand Down Expand Up @@ -200,11 +218,9 @@ class GroupTest {
assertEquals(ReactionSchema.Unicode, content?.schema)
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun testCanStreamGroupMessages() = kotlinx.coroutines.test.runTest {
val group = boClient.conversations.newGroup(listOf(alix.walletAddress.lowercase()))

group.streamMessages().test {
group.send("hi")
assertEquals("hi", awaitItem().body)
Expand All @@ -213,7 +229,6 @@ class GroupTest {
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun testCanStreamDecryptedGroupMessages() = kotlinx.coroutines.test.runTest {
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
Expand All @@ -226,7 +241,6 @@ class GroupTest {
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun testCanStreamGroups() = kotlinx.coroutines.test.runTest {
boClient.conversations.streamGroups().test {
Expand All @@ -239,7 +253,6 @@ class GroupTest {
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun testCanStreamGroupsAndConversations() = kotlinx.coroutines.test.runTest {
boClient.conversations.streamAll().test {
Expand Down
4 changes: 3 additions & 1 deletion library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
import uniffi.xmtpv3.FfiXmtpClient
import uniffi.xmtpv3.LegacyIdentitySource
import uniffi.xmtpv3.createClient
import uniffi.xmtpv3.getVersionInfo
import java.io.File
import java.nio.charset.StandardCharsets
import java.security.KeyStore
Expand Down Expand Up @@ -81,6 +82,7 @@ class Client() {
lateinit var conversations: Conversations
var logger: XMTPLogger = XMTPLogger()
var libXMTPClient: FfiXmtpClient? = null
val libXMTPVersion: String = getVersionInfo()

companion object {
private const val TAG = "Client"
Expand Down Expand Up @@ -347,7 +349,7 @@ class Client() {
throw XMTPException("No signer passed but signer was required.")
}
}

Log.i(TAG, "LibXMTP $libXMTPVersion")
return v3Client
}

Expand Down
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 @@ -128,6 +128,10 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
)
}

fun isActive(): Boolean {
return libXMTPGroup.isActive()
}

fun addMembers(addresses: List<String>) {
runBlocking { libXMTPGroup.addMembers(addresses) }
}
Expand Down
54 changes: 54 additions & 0 deletions library/src/main/java/xmtpv3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_method_ffigroup_id(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_method_ffigroup_is_active(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): Byte
fun uniffi_xmtpv3_fn_method_ffigroup_list_members(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_method_ffigroup_remove_members(`ptr`: Pointer,`accountAddresses`: RustBuffer.ByValue,
Expand All @@ -427,6 +429,8 @@ internal interface _UniFFILib : Library {
): Unit
fun uniffi_xmtpv3_fn_method_ffistreamcloser_end(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): Unit
fun uniffi_xmtpv3_fn_method_ffistreamcloser_is_closed(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): Byte
fun uniffi_xmtpv3_fn_free_ffiv2apiclient(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): Unit
fun uniffi_xmtpv3_fn_method_ffiv2apiclient_batch_query(`ptr`: Pointer,`req`: RustBuffer.ByValue,
Expand Down Expand Up @@ -475,6 +479,8 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_func_generate_private_preferences_topic_identifier(`privateKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_func_get_version_info(_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_func_keccak256(`input`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_xmtpv3_fn_func_public_key_from_private_key_k256(`privateKeyBytes`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
Expand Down Expand Up @@ -615,6 +621,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_xmtpv3_checksum_func_generate_private_preferences_topic_identifier(
): Short
fun uniffi_xmtpv3_checksum_func_get_version_info(
): Short
fun uniffi_xmtpv3_checksum_func_keccak256(
): Short
fun uniffi_xmtpv3_checksum_func_public_key_from_private_key_k256(
Expand Down Expand Up @@ -649,6 +657,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_id(
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_is_active(
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_list_members(
): Short
fun uniffi_xmtpv3_checksum_method_ffigroup_remove_members(
Expand All @@ -661,6 +671,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_xmtpv3_checksum_method_ffistreamcloser_end(
): Short
fun uniffi_xmtpv3_checksum_method_ffistreamcloser_is_closed(
): Short
fun uniffi_xmtpv3_checksum_method_ffiv2apiclient_batch_query(
): Short
fun uniffi_xmtpv3_checksum_method_ffiv2apiclient_publish(
Expand Down Expand Up @@ -726,6 +738,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_xmtpv3_checksum_func_generate_private_preferences_topic_identifier() != 5952.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_func_get_version_info() != 3533.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_func_keccak256() != 17749.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -777,6 +792,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_id() != 35243.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_is_active() != 27808.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffigroup_list_members() != 15786.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand All @@ -795,6 +813,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_xmtpv3_checksum_method_ffistreamcloser_end() != 47211.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffistreamcloser_is_closed() != 37884.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffiv2apiclient_batch_query() != 10812.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -1379,6 +1400,7 @@ public interface FfiGroupInterface {
fun `createdAtNs`(): Long@Throws(GenericException::class)
fun `findMessages`(`opts`: FfiListMessagesOptions): List<FfiMessage>
fun `id`(): ByteArray@Throws(GenericException::class)
fun `isActive`(): Boolean@Throws(GenericException::class)
fun `listMembers`(): List<FfiGroupMember>@Throws(GenericException::class)
suspend fun `removeMembers`(`accountAddresses`: List<String>)@Throws(GenericException::class)
suspend fun `send`(`contentBytes`: ByteArray)@Throws(GenericException::class)
Expand Down Expand Up @@ -1461,6 +1483,18 @@ class FfiGroup(
}


@Throws(GenericException::class)override fun `isActive`(): Boolean =
callWithPointer {
rustCallWithError(GenericException) { _status ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffigroup_is_active(it,

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


@Throws(GenericException::class)override fun `listMembers`(): List<FfiGroupMember> =
callWithPointer {
rustCallWithError(GenericException) { _status ->
Expand Down Expand Up @@ -1590,6 +1624,7 @@ public object FfiConverterTypeFfiGroup: FfiConverter<FfiGroup, Pointer> {
public interface FfiStreamCloserInterface {

fun `end`()
fun `isClosed`(): Boolean
companion object
}

Expand Down Expand Up @@ -1621,6 +1656,17 @@ class FfiStreamCloser(
}


override fun `isClosed`(): Boolean =
callWithPointer {
rustCall() { _status ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_ffistreamcloser_is_closed(it,

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




Expand Down Expand Up @@ -3511,6 +3557,14 @@ fun `generatePrivatePreferencesTopicIdentifier`(`privateKey`: ByteArray): String
}


fun `getVersionInfo`(): String {
return FfiConverterString.lift(
rustCall() { _status ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_func_get_version_info(_status)
})
}


fun `keccak256`(`input`: ByteArray): ByteArray {
return FfiConverterByteArray.lift(
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 be8c3bc

Please sign in to comment.