Skip to content

Commit a59fe92

Browse files
authored
Fix transport error (#179)
* add dates to example and a test around removing members * get latest libxmtp * test on local
1 parent be8c3bc commit a59fe92

File tree

10 files changed

+119
-13
lines changed

10 files changed

+119
-13
lines changed

example/src/main/java/org/xmtp/android/example/message/MessageViewHolder.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import org.xmtp.android.example.R
1111
import org.xmtp.android.example.conversation.ConversationDetailViewModel
1212
import org.xmtp.android.example.databinding.ListItemMessageBinding
1313
import org.xmtp.android.example.extension.margins
14-
import org.xmtp.proto.mls.message.contents.TranscriptMessages
1514
import uniffi.xmtpv3.org.xmtp.android.library.codecs.GroupMembershipChanges
15+
import java.text.SimpleDateFormat
16+
import java.util.Locale
1617

1718
class MessageViewHolder(
1819
private val binding: ListItemMessageBinding,
@@ -45,6 +46,9 @@ class MessageViewHolder(
4546
binding.messageContainer.layoutParams = params
4647
if (item.message.content<Any>() is String) {
4748
binding.messageBody.text = item.message.body
49+
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
50+
binding.messageDate.text = sdf.format(item.message.sent)
51+
4852
} else if (item.message.content<Any>() is GroupMembershipChanges) {
4953
val changes = item.message.content() as? GroupMembershipChanges
5054
binding.messageBody.text =

example/src/main/res/layout/list_item_message.xml

+18-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@
1515
app:cardCornerRadius="8dp"
1616
app:layout_constraintTop_toTopOf="parent"
1717
tools:ignore="MissingConstraints">
18-
19-
<TextView
20-
android:id="@+id/messageBody"
18+
<LinearLayout
2119
android:layout_width="wrap_content"
22-
android:layout_height="wrap_content"
23-
android:textSize="16sp"
24-
android:layout_margin="8dp" />
20+
android:layout_height="wrap_content">
21+
<TextView
22+
android:id="@+id/messageBody"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:textSize="16sp"
26+
android:layout_margin="8dp" />
27+
<TextView
28+
android:id="@+id/messageDate"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:textSize="16sp"
32+
android:layout_margin="8dp"
33+
/>
34+
</LinearLayout>
35+
36+
2537

2638
</androidx.cardview.widget.CardView>
2739

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

+17
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,23 @@ class ClientTest {
126126
assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
127127
}
128128

129+
@Test
130+
fun testCreatesAV3DevClient() {
131+
val context = InstrumentationRegistry.getInstrumentation().targetContext
132+
val fakeWallet = PrivateKeyBuilder()
133+
val client =
134+
Client().create(
135+
account = fakeWallet,
136+
options = ClientOptions(
137+
ClientOptions.Api(XMTPEnvironment.DEV, true),
138+
enableAlphaMls = true,
139+
appContext = context
140+
)
141+
)
142+
val v3Client = client.libXMTPClient
143+
assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
144+
}
145+
129146
@Test
130147
fun testDoesNotCreateAV3Client() {
131148
val fakeWallet = PrivateKeyBuilder()

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

+20
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ class GroupTest {
112112
)
113113
}
114114

115+
@Test
116+
fun testCanRemoveGroupMembersWhenNotCreator() {
117+
boClient.conversations.newGroup(
118+
listOf(
119+
alix.walletAddress,
120+
caro.walletAddress
121+
)
122+
)
123+
runBlocking { alixClient.conversations.syncGroups() }
124+
val group = alixClient.conversations.listGroups().first()
125+
group.removeMembers(listOf(caro.walletAddress))
126+
assertEquals(
127+
group.memberAddresses().sorted(),
128+
listOf(
129+
alix.walletAddress.lowercase(),
130+
bo.walletAddress.lowercase()
131+
).sorted()
132+
)
133+
}
134+
115135
@Test
116136
fun testIsActiveReturnsCorrectly() {
117137
val group = boClient.conversations.newGroup(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ data class Conversations(
105105
}
106106

107107
val group = runBlocking {
108-
libXMTPConversations?.createGroup(accountAddresses)
108+
libXMTPConversations?.createGroup(accountAddresses, permissions = null)
109109
?: throw XMTPException("Client does not support Groups")
110110
}
111111
return Group(client, group)

library/src/main/java/xmtpv3.kt

+58-5
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ internal interface _UniFFILib : Library {
395395

396396
fun uniffi_xmtpv3_fn_free_fficonversations(`ptr`: Pointer,_uniffi_out_err: RustCallStatus,
397397
): Unit
398-
fun uniffi_xmtpv3_fn_method_fficonversations_create_group(`ptr`: Pointer,`accountAddresses`: RustBuffer.ByValue,
398+
fun uniffi_xmtpv3_fn_method_fficonversations_create_group(`ptr`: Pointer,`accountAddresses`: RustBuffer.ByValue,`permissions`: RustBuffer.ByValue,
399399
): Pointer
400400
fun uniffi_xmtpv3_fn_method_fficonversations_list(`ptr`: Pointer,`opts`: RustBuffer.ByValue,
401401
): Pointer
@@ -768,7 +768,7 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
768768
if (lib.uniffi_xmtpv3_checksum_func_verify_k256_sha256() != 31332.toShort()) {
769769
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
770770
}
771-
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 45500.toShort()) {
771+
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 16460.toShort()) {
772772
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
773773
}
774774
if (lib.uniffi_xmtpv3_checksum_method_fficonversations_list() != 44067.toShort()) {
@@ -1256,7 +1256,7 @@ abstract class FFIObject(
12561256

12571257
public interface FfiConversationsInterface {
12581258
@Throws(GenericException::class)
1259-
suspend fun `createGroup`(`accountAddresses`: List<String>): FfiGroup@Throws(GenericException::class)
1259+
suspend fun `createGroup`(`accountAddresses`: List<String>, `permissions`: GroupPermissions?): FfiGroup@Throws(GenericException::class)
12601260
suspend fun `list`(`opts`: FfiListConversationsOptions): List<FfiGroup>@Throws(GenericException::class)
12611261
suspend fun `stream`(`callback`: FfiConversationCallback): FfiStreamCloser@Throws(GenericException::class)
12621262
suspend fun `sync`()
@@ -1284,12 +1284,12 @@ class FfiConversations(
12841284

12851285
@Throws(GenericException::class)
12861286
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
1287-
override suspend fun `createGroup`(`accountAddresses`: List<String>) : FfiGroup {
1287+
override suspend fun `createGroup`(`accountAddresses`: List<String>, `permissions`: GroupPermissions?) : FfiGroup {
12881288
return uniffiRustCallAsync(
12891289
callWithPointer { thisPtr ->
12901290
_UniFFILib.INSTANCE.uniffi_xmtpv3_fn_method_fficonversations_create_group(
12911291
thisPtr,
1292-
FfiConverterSequenceString.lower(`accountAddresses`),
1292+
FfiConverterSequenceString.lower(`accountAddresses`),FfiConverterOptionalTypeGroupPermissions.lower(`permissions`),
12931293
)
12941294
},
12951295
{ future, continuation -> _UniFFILib.INSTANCE.ffi_xmtpv3_rust_future_poll_pointer(future, continuation) },
@@ -2613,6 +2613,30 @@ public object FfiConverterTypeGenericError : FfiConverterRustBuffer<GenericExcep
26132613

26142614

26152615

2616+
enum class GroupPermissions {
2617+
EVERYONE_IS_ADMIN,GROUP_CREATOR_IS_ADMIN;
2618+
companion object
2619+
}
2620+
2621+
public object FfiConverterTypeGroupPermissions: FfiConverterRustBuffer<GroupPermissions> {
2622+
override fun read(buf: ByteBuffer) = try {
2623+
GroupPermissions.values()[buf.getInt() - 1]
2624+
} catch (e: IndexOutOfBoundsException) {
2625+
throw RuntimeException("invalid enum value, something is very wrong!!", e)
2626+
}
2627+
2628+
override fun allocationSize(value: GroupPermissions) = 4
2629+
2630+
override fun write(value: GroupPermissions, buf: ByteBuffer) {
2631+
buf.putInt(value.ordinal + 1)
2632+
}
2633+
}
2634+
2635+
2636+
2637+
2638+
2639+
26162640
enum class LegacyIdentitySource {
26172641
NONE,STATIC,NETWORK,KEY_GENERATOR;
26182642
companion object
@@ -3283,6 +3307,35 @@ public object FfiConverterOptionalTypeFfiPagingInfo: FfiConverterRustBuffer<FfiP
32833307

32843308

32853309

3310+
public object FfiConverterOptionalTypeGroupPermissions: FfiConverterRustBuffer<GroupPermissions?> {
3311+
override fun read(buf: ByteBuffer): GroupPermissions? {
3312+
if (buf.get().toInt() == 0) {
3313+
return null
3314+
}
3315+
return FfiConverterTypeGroupPermissions.read(buf)
3316+
}
3317+
3318+
override fun allocationSize(value: GroupPermissions?): Int {
3319+
if (value == null) {
3320+
return 1
3321+
} else {
3322+
return 1 + FfiConverterTypeGroupPermissions.allocationSize(value)
3323+
}
3324+
}
3325+
3326+
override fun write(value: GroupPermissions?, buf: ByteBuffer) {
3327+
if (value == null) {
3328+
buf.put(0)
3329+
} else {
3330+
buf.put(1)
3331+
FfiConverterTypeGroupPermissions.write(value, buf)
3332+
}
3333+
}
3334+
}
3335+
3336+
3337+
3338+
32863339
public object FfiConverterSequenceBoolean: FfiConverterRustBuffer<List<Boolean>> {
32873340
override fun read(buf: ByteBuffer): List<Boolean> {
32883341
val len = buf.getInt()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)