Skip to content

Commit

Permalink
update the bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 15, 2024
1 parent c54698e commit 3ac07b0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
21 changes: 9 additions & 12 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.xmtp.android.library.codecs.TextCodec
import org.xmtp.android.library.libxmtp.Message
import org.xmtp.android.library.libxmtp.XMTPLogger
import org.xmtp.android.library.messages.rawData
import uniffi.xmtpv3.FfiConversationType
import uniffi.xmtpv3.FfiDeviceSyncKind
import uniffi.xmtpv3.FfiXmtpClient
import uniffi.xmtpv3.createClient
Expand Down Expand Up @@ -218,12 +219,10 @@ class Client() {
fun findConversation(conversationId: String): Conversation? {
return try {
val conversation = ffiClient.conversation(conversationId.hexToByteArray())
if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(this, conversation))
} else if (conversation.groupMetadata().conversationType() == "group") {
Conversation.Group(Group(this, conversation))
} else {
null
when (conversation.conversationType()) {
FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation))
FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation))
else -> null
}
} catch (e: Exception) {
null
Expand All @@ -236,12 +235,10 @@ class Client() {
val conversationId = matchResult?.groupValues?.get(1) ?: ""
return try {
val conversation = ffiClient.conversation(conversationId.hexToByteArray())
if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(this, conversation))
} else if (conversation.groupMetadata().conversationType() == "group") {
Conversation.Group(Group(this, conversation))
} else {
null
when (conversation.conversationType()) {
FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation))
FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation))
else -> null
}
} catch (e: Exception) {
null
Expand Down
22 changes: 10 additions & 12 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.callbackFlow
import org.xmtp.android.library.libxmtp.Message
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiConversationCallback
import uniffi.xmtpv3.FfiConversationType
import uniffi.xmtpv3.FfiConversations
import uniffi.xmtpv3.FfiCreateGroupOptions
import uniffi.xmtpv3.FfiDirection
Expand Down Expand Up @@ -41,10 +42,9 @@ data class Conversations(

suspend fun fromWelcome(envelopeBytes: ByteArray): Conversation {
val conversation = ffiConversations.processStreamedWelcomeMessage(envelopeBytes)
return if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(client, conversation))
} else {
Conversation.Group(Group(client, conversation))
return when (conversation.conversationType()) {
FfiConversationType.DM -> Conversation.Dm(Dm(client, conversation))
else -> Conversation.Group(Group(client, conversation))
}
}

Expand Down Expand Up @@ -250,21 +250,19 @@ data class Conversations(
}

private fun FfiConversation.toConversation(): Conversation {
return if (groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(client, this))
} else {
Conversation.Group(Group(client, this))
return when (conversationType()) {
FfiConversationType.DM -> Conversation.Dm(Dm(client, this))
else -> Conversation.Group(Group(client, this))
}
}

fun stream(type: ConversationType = ConversationType.ALL): Flow<Conversation> =
callbackFlow {
val conversationCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiConversation) {
if (conversation.groupMetadata().conversationType() == "dm") {
trySend(Conversation.Dm(Dm(client, conversation)))
} else {
trySend(Conversation.Group(Group(client, conversation)))
when (conversation.conversationType()) {
FfiConversationType.DM -> trySend(Conversation.Dm(Dm(client, conversation)))
else -> trySend(Conversation.Group(Group(client, conversation)))
}
}

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 3ac07b0

Please sign in to comment.