Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isActive to Groups #176

Merged
merged 8 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ class GroupTest {
)
}

@Test
fun testIsActiveReturnsCorrectly() {
val group = boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
)
)
assert(group.isActive())
group.removeMembers(listOf(bo.walletAddress))
assert(!group.isActive())
}

@Test
fun testCanListGroups() {
boClient.conversations.newGroup(listOf(alix.walletAddress))
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, "The libxmtp version is: $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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should have been a libxmtp-version.txt generated alongside the .kt definition, could we check that in too?

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
Loading