Skip to content

Commit

Permalink
Fix transport error (#179)
Browse files Browse the repository at this point in the history
* add dates to example and a test around removing members

* get latest libxmtp

* test on local
  • Loading branch information
nplasterer authored Feb 16, 2024
1 parent be8c3bc commit a59fe92
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import org.xmtp.android.example.R
import org.xmtp.android.example.conversation.ConversationDetailViewModel
import org.xmtp.android.example.databinding.ListItemMessageBinding
import org.xmtp.android.example.extension.margins
import org.xmtp.proto.mls.message.contents.TranscriptMessages
import uniffi.xmtpv3.org.xmtp.android.library.codecs.GroupMembershipChanges
import java.text.SimpleDateFormat
import java.util.Locale

class MessageViewHolder(
private val binding: ListItemMessageBinding,
Expand Down Expand Up @@ -45,6 +46,9 @@ class MessageViewHolder(
binding.messageContainer.layoutParams = params
if (item.message.content<Any>() is String) {
binding.messageBody.text = item.message.body
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
binding.messageDate.text = sdf.format(item.message.sent)

} else if (item.message.content<Any>() is GroupMembershipChanges) {
val changes = item.message.content() as? GroupMembershipChanges
binding.messageBody.text =
Expand Down
24 changes: 18 additions & 6 deletions example/src/main/res/layout/list_item_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@
app:cardCornerRadius="8dp"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">

<TextView
android:id="@+id/messageBody"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_margin="8dp" />
android:layout_height="wrap_content">
<TextView
android:id="@+id/messageBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_margin="8dp" />
<TextView
android:id="@+id/messageDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_margin="8dp"
/>
</LinearLayout>



</androidx.cardview.widget.CardView>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ class ClientTest {
assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
}

@Test
fun testCreatesAV3DevClient() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val fakeWallet = PrivateKeyBuilder()
val client =
Client().create(
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.DEV, true),
enableAlphaMls = true,
appContext = context
)
)
val v3Client = client.libXMTPClient
assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
}

@Test
fun testDoesNotCreateAV3Client() {
val fakeWallet = PrivateKeyBuilder()
Expand Down
20 changes: 20 additions & 0 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ class GroupTest {
)
}

@Test
fun testCanRemoveGroupMembersWhenNotCreator() {
boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
)
)
runBlocking { alixClient.conversations.syncGroups() }
val group = alixClient.conversations.listGroups().first()
group.removeMembers(listOf(caro.walletAddress))
assertEquals(
group.memberAddresses().sorted(),
listOf(
alix.walletAddress.lowercase(),
bo.walletAddress.lowercase()
).sorted()
)
}

@Test
fun testIsActiveReturnsCorrectly() {
val group = boClient.conversations.newGroup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ data class Conversations(
}

val group = runBlocking {
libXMTPConversations?.createGroup(accountAddresses)
libXMTPConversations?.createGroup(accountAddresses, permissions = null)
?: throw XMTPException("Client does not support Groups")
}
return Group(client, group)
Expand Down
63 changes: 58 additions & 5 deletions library/src/main/java/xmtpv3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ internal interface _UniFFILib : Library {

fun uniffi_xmtpv3_fn_free_fficonversations(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
): Unit
fun uniffi_xmtpv3_fn_method_fficonversations_create_group(`ptr`: Pointer,`accountAddresses`: RustBuffer.ByValue,
fun uniffi_xmtpv3_fn_method_fficonversations_create_group(`ptr`: Pointer,`accountAddresses`: RustBuffer.ByValue,`permissions`: RustBuffer.ByValue,
): Pointer
fun uniffi_xmtpv3_fn_method_fficonversations_list(`ptr`: Pointer,`opts`: RustBuffer.ByValue,
): Pointer
Expand Down Expand Up @@ -768,7 +768,7 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_xmtpv3_checksum_func_verify_k256_sha256() != 31332.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 45500.toShort()) {
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 16460.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_list() != 44067.toShort()) {
Expand Down Expand Up @@ -1256,7 +1256,7 @@ abstract class FFIObject(

public interface FfiConversationsInterface {
@Throws(GenericException::class)
suspend fun `createGroup`(`accountAddresses`: List<String>): FfiGroup@Throws(GenericException::class)
suspend fun `createGroup`(`accountAddresses`: List<String>, `permissions`: GroupPermissions?): FfiGroup@Throws(GenericException::class)
suspend fun `list`(`opts`: FfiListConversationsOptions): List<FfiGroup>@Throws(GenericException::class)
suspend fun `stream`(`callback`: FfiConversationCallback): FfiStreamCloser@Throws(GenericException::class)
suspend fun `sync`()
Expand Down Expand Up @@ -1284,12 +1284,12 @@ class FfiConversations(

@Throws(GenericException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `createGroup`(`accountAddresses`: List<String>) : FfiGroup {
override suspend fun `createGroup`(`accountAddresses`: List<String>, `permissions`: GroupPermissions?) : FfiGroup {
return uniffiRustCallAsync(
callWithPointer { thisPtr ->
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_fficonversations_create_group(
thisPtr,
FfiConverterSequenceString.lower(`accountAddresses`),
FfiConverterSequenceString.lower(`accountAddresses`),FfiConverterOptionalTypeGroupPermissions.lower(`permissions`),
)
},
{ future, continuation -> _UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_poll_pointer(future, continuation) },
Expand Down Expand Up @@ -2613,6 +2613,30 @@ public object FfiConverterTypeGenericError : FfiConverterRustBuffer<GenericExcep



enum class GroupPermissions {
EVERYONE_IS_ADMIN,GROUP_CREATOR_IS_ADMIN;
companion object
}

public object FfiConverterTypeGroupPermissions: FfiConverterRustBuffer<GroupPermissions> {
override fun read(buf: ByteBuffer) = try {
GroupPermissions.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}

override fun allocationSize(value: GroupPermissions) = 4

override fun write(value: GroupPermissions, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}






enum class LegacyIdentitySource {
NONE,STATIC,NETWORK,KEY_GENERATOR;
companion object
Expand Down Expand Up @@ -3283,6 +3307,35 @@ public object FfiConverterOptionalTypeFfiPagingInfo: FfiConverterRustBuffer<FfiP



public object FfiConverterOptionalTypeGroupPermissions: FfiConverterRustBuffer<GroupPermissions?> {
override fun read(buf: ByteBuffer): GroupPermissions? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeGroupPermissions.read(buf)
}

override fun allocationSize(value: GroupPermissions?): Int {
if (value == null) {
return 1
} else {
return 1 + FfiConverterTypeGroupPermissions.allocationSize(value)
}
}

override fun write(value: GroupPermissions?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeGroupPermissions.write(value, buf)
}
}
}




public object FfiConverterSequenceBoolean: FfiConverterRustBuffer<List<Boolean>> {
override fun read(buf: ByteBuffer): List<Boolean> {
val len = buf.getInt()
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 a59fe92

Please sign in to comment.