Skip to content

Commit

Permalink
get on the latest version of libxmtp
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 16, 2024
1 parent 4e42b28 commit eadcf46
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class DmTest {

@Test
fun testCanCreateADm() {

val dm = runBlocking {
boClient.conversations.newConversation(alix.walletAddress)
}
}
@Test
fun testCanListDmMembers() {
Expand Down
12 changes: 11 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 @@ -567,10 +567,20 @@ class Client() {
}
}

@Deprecated("Find now includes DMs and Groups", replaceWith = ReplaceWith("findConversation"))
fun findGroup(groupId: String): Group? {
val client = v3Client ?: throw XMTPException("Error no V3 client initialized")
try {
return Group(this, client.group(groupId.hexToByteArray()))
return Group(this, client.conversation(groupId.hexToByteArray()))
} catch (e: Exception) {
return null
}
}

fun findConversation(conversationId: String): Group? {
val client = v3Client ?: throw XMTPException("Error no V3 client initialized")
try {
return Group(this, client.conversation(conversationId.hexToByteArray()))
} catch (e: Exception) {
return null
}
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ enum class EntryType {
fun toFfiConsentEntityType(option: EntryType): FfiConsentEntityType {
return when (option) {
EntryType.ADDRESS -> FfiConsentEntityType.ADDRESS
EntryType.GROUP_ID -> FfiConsentEntityType.GROUP_ID
EntryType.GROUP_ID -> FfiConsentEntityType.CONVERSATION_ID
EntryType.INBOX_ID -> FfiConsentEntityType.INBOX_ID
}
}

fun fromFfiConsentEntityType(option: FfiConsentEntityType): EntryType {
return when (option) {
FfiConsentEntityType.ADDRESS -> EntryType.ADDRESS
FfiConsentEntityType.GROUP_ID -> EntryType.GROUP_ID
FfiConsentEntityType.CONVERSATION_ID -> EntryType.GROUP_ID
FfiConsentEntityType.INBOX_ID -> EntryType.INBOX_ID
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ class ConsentList(
client.v3Client?.let {
return ConsentState.fromFfiConsentState(
it.getConsentState(
FfiConsentEntityType.GROUP_ID,
FfiConsentEntityType.CONVERSATION_ID,
groupId
)
)
Expand Down
24 changes: 15 additions & 9 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import uniffi.xmtpv3.FfiConversationCallback
import uniffi.xmtpv3.FfiConversations
import uniffi.xmtpv3.FfiCreateGroupOptions
import uniffi.xmtpv3.FfiEnvelope
import uniffi.xmtpv3.FfiGroup
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiListConversationsOptions
import uniffi.xmtpv3.FfiMessage
import uniffi.xmtpv3.FfiMessageCallback
Expand Down Expand Up @@ -191,17 +191,23 @@ data class Conversations(
libXMTPConversations?.sync()
}

// Sync all existing local conversation data from the network (Note: call syncConversations() first to get the latest list of conversations)
suspend fun syncAllConversations(): UInt? {
return libXMTPConversations?.syncAllConversations()
}

// Sync all existing local groups data from the network (Note: call syncGroups() first to get the latest list of groups)
@Deprecated("Sync now includes DMs and Groups", replaceWith = ReplaceWith("syncAllConversations"))
suspend fun syncAllGroups(): UInt? {
return libXMTPConversations?.syncAllGroups()
return libXMTPConversations?.syncAllConversations()
}

suspend fun listGroups(
after: Date? = null,
before: Date? = null,
limit: Int? = null,
): List<Group> {
return libXMTPConversations?.list(
return libXMTPConversations?.listGroups(
opts = FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
Expand Down Expand Up @@ -670,22 +676,22 @@ data class Conversations(

private fun streamGroupConversations(): Flow<Conversation> = callbackFlow {
val groupCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiGroup) {
override fun onConversation(conversation: FfiConversation) {
trySend(Conversation.Group(Group(client, conversation)))
}
}
val stream = libXMTPConversations?.stream(groupCallback)
val stream = libXMTPConversations?.streamGroups(groupCallback)
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}

fun streamGroups(): Flow<Group> = callbackFlow {
val groupCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiGroup) {
override fun onConversation(conversation: FfiConversation) {
trySend(Group(client, conversation))
}
}
val stream = libXMTPConversations?.stream(groupCallback)
val stream = libXMTPConversations?.streamGroups(groupCallback)
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}
Expand All @@ -699,7 +705,7 @@ data class Conversations(
}
}
}
val stream = libXMTPConversations?.streamAllMessages(messageCallback)
val stream = libXMTPConversations?.streamAllGroupMessages(messageCallback)
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}
Expand All @@ -713,7 +719,7 @@ data class Conversations(
}
}
}
val stream = libXMTPConversations?.streamAllMessages(messageCallback)
val stream = libXMTPConversations?.streamAllGroupMessages(messageCallback)
?: throw XMTPException("Client does not support Groups")
awaitClose { stream.end() }
}
Expand Down
15 changes: 5 additions & 10 deletions library/src/main/java/org/xmtp/android/library/Dm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@ import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.messages.PagingInfoSortDirection
import org.xmtp.android.library.messages.Topic
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiConversationMetadata
import uniffi.xmtpv3.FfiDeliveryStatus
import uniffi.xmtpv3.FfiGroup
import uniffi.xmtpv3.FfiGroupMetadata
import uniffi.xmtpv3.FfiGroupPermissions
import uniffi.xmtpv3.FfiListMessagesOptions
import uniffi.xmtpv3.FfiMessage
import uniffi.xmtpv3.FfiMessageCallback
import uniffi.xmtpv3.FfiMetadataField
import uniffi.xmtpv3.FfiPermissionUpdateType
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionOption
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionPolicySet
import java.util.Date
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.DurationUnit

class Dm(val client: Client, private val libXMTPGroup: FfiGroup) {
class Dm(val client: Client, private val libXMTPGroup: FfiConversation) {
val id: String
get() = libXMTPGroup.id().toHex()

Expand All @@ -38,7 +33,7 @@ class Dm(val client: Client, private val libXMTPGroup: FfiGroup) {
val createdAt: Date
get() = Date(libXMTPGroup.createdAtNs() / 1_000_000)

private val metadata: FfiGroupMetadata
private val metadata: FfiConversationMetadata
get() = libXMTPGroup.groupMetadata()

val name: String
Expand Down Expand Up @@ -171,7 +166,7 @@ class Dm(val client: Client, private val libXMTPGroup: FfiGroup) {
}

suspend fun processMessage(envelopeBytes: ByteArray): MessageV3 {
val message = libXMTPGroup.processStreamedGroupMessage(envelopeBytes)
val message = libXMTPGroup.processStreamedConversationMessage(envelopeBytes)
return MessageV3(client, message)
}

Expand Down
10 changes: 5 additions & 5 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import org.xmtp.android.library.messages.PagingInfoSortDirection
import org.xmtp.android.library.messages.Topic
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import uniffi.xmtpv3.FfiDeliveryStatus
import uniffi.xmtpv3.FfiGroup
import uniffi.xmtpv3.FfiGroupMetadata
import uniffi.xmtpv3.FfiConversation
import uniffi.xmtpv3.FfiConversationMetadata
import uniffi.xmtpv3.FfiGroupPermissions
import uniffi.xmtpv3.FfiListMessagesOptions
import uniffi.xmtpv3.FfiMessage
Expand All @@ -28,7 +28,7 @@ import java.util.Date
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.DurationUnit

class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
class Group(val client: Client, private val libXMTPGroup: FfiConversation) {
val id: String
get() = libXMTPGroup.id().toHex()

Expand All @@ -38,7 +38,7 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
val createdAt: Date
get() = Date(libXMTPGroup.createdAtNs() / 1_000_000)

private val metadata: FfiGroupMetadata
private val metadata: FfiConversationMetadata
get() = libXMTPGroup.groupMetadata()

private val permissions: FfiGroupPermissions
Expand Down Expand Up @@ -174,7 +174,7 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
}

suspend fun processMessage(envelopeBytes: ByteArray): MessageV3 {
val message = libXMTPGroup.processStreamedGroupMessage(envelopeBytes)
val message = libXMTPGroup.processStreamedConversationMessage(envelopeBytes)
return MessageV3(client, message)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.xmtp.android.library.libxmtp

import org.xmtp.android.library.ConsentState
import uniffi.xmtpv3.FfiGroupMember
import uniffi.xmtpv3.FfiConversationMember
import uniffi.xmtpv3.FfiPermissionLevel

enum class PermissionLevel {
MEMBER, ADMIN, SUPER_ADMIN
}
class Member(private val ffiMember: FfiGroupMember) {
class Member(private val ffiMember: FfiConversationMember) {

val inboxId: String
get() = ffiMember.inboxId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.messages.Topic
import org.xmtp.android.library.toHex
import uniffi.xmtpv3.FfiDeliveryStatus
import uniffi.xmtpv3.FfiGroupMessageKind
import uniffi.xmtpv3.FfiConversationMessageKind
import uniffi.xmtpv3.FfiMessage
import java.util.Date

Expand Down Expand Up @@ -47,7 +47,7 @@ data class MessageV3(val client: Client, private val libXMTPMessage: FfiMessage)
sent = sentAt,
deliveryStatus = deliveryStatus
)
if (decodedMessage.encodedContent.type == ContentTypeGroupUpdated && libXMTPMessage.kind != FfiGroupMessageKind.MEMBERSHIP_CHANGE) {
if (decodedMessage.encodedContent.type == ContentTypeGroupUpdated && libXMTPMessage.kind != FfiConversationMessageKind.MEMBERSHIP_CHANGE) {
throw XMTPException("Error decoding group membership change")
}
return decodedMessage
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 eadcf46

Please sign in to comment.