Skip to content

Commit

Permalink
get on the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 15, 2024
1 parent 86d6ae2 commit 701839e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 25 deletions.
12 changes: 6 additions & 6 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class DmTest {
assertEquals(dm.messages().first().body, "gm")
assertEquals(dm.messages().first().id, messageId)
assertEquals(dm.messages().first().deliveryStatus, MessageDeliveryStatus.PUBLISHED)
assertEquals(dm.messages().size, 3)
assertEquals(dm.messages().size, 2)

runBlocking { alixClient.conversations.syncConversations() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
Expand All @@ -181,12 +181,12 @@ class DmTest {
dm.send("gm")
}

assertEquals(dm.messages().size, 3)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 3)
assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
runBlocking { dm.sync() }
assertEquals(dm.messages().size, 3)
assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 0)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 3)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)

runBlocking { alixClient.conversations.syncConversations() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
Expand Down Expand Up @@ -219,7 +219,7 @@ class DmTest {
runBlocking { dm.sync() }

val messages = dm.messages()
assertEquals(messages.size, 3)
assertEquals(messages.size, 2)
val content: Reaction? = messages.first().content()
assertEquals("U+1F603", content?.content)
assertEquals(messageToReact.id, content?.reference)
Expand Down
24 changes: 11 additions & 13 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import org.xmtp.android.library.messages.walletAddress
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.BatchQueryResponse
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
import uniffi.xmtpv3.FfiConversationType
import uniffi.xmtpv3.FfiDeviceSyncKind
import uniffi.xmtpv3.FfiV2SubscribeRequest
import uniffi.xmtpv3.FfiV2Subscription
import uniffi.xmtpv3.FfiV2SubscriptionCallback
Expand Down Expand Up @@ -616,12 +618,10 @@ class Client() {
fun findConversation(conversationId: String): Conversation? {
val client = v3Client ?: throw XMTPException("Error no V3 client initialized")
val conversation = client.conversation(conversationId.hexToByteArray())
return if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(this, conversation))
} else if (conversation.groupMetadata().conversationType() == "group") {
Conversation.Group(Group(this, conversation))
} else {
null
return when (conversation.conversationType()) {
FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation))
FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation))
else -> null
}
}

Expand All @@ -631,12 +631,10 @@ class Client() {
val matchResult = regex.find(topic)
val conversationId = matchResult?.groupValues?.get(1) ?: ""
val conversation = client.conversation(conversationId.hexToByteArray())
return if (conversation.groupMetadata().conversationType() == "dm") {
Conversation.Dm(Dm(this, conversation))
} else if (conversation.groupMetadata().conversationType() == "group") {
Conversation.Group(Group(this, conversation))
} else {
null
return when (conversation.conversationType()) {
FfiConversationType.GROUP -> Conversation.Group(Group(this, conversation))
FfiConversationType.DM -> Conversation.Dm(Dm(this, conversation))
else -> null
}
}

Expand Down Expand Up @@ -775,7 +773,7 @@ class Client() {
}

suspend fun requestMessageHistorySync() {
v3Client?.requestHistorySync() ?: throw XMTPException("Error no V3 client initialized")
v3Client?.sendSyncRequest(FfiDeviceSyncKind.MESSAGES) ?: throw XMTPException("Error no V3 client initialized")
}

suspend fun revokeAllOtherInstallations(signingKey: SigningKey) {
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/org/xmtp/android/library/ConversationV1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.xmtp.android.library.messages.walletAddress
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import uniffi.xmtpv3.FfiEnvelope
import uniffi.xmtpv3.FfiV2SubscriptionCallback
import uniffi.xmtpv3.GenericException
import java.util.Date

data class ConversationV1(
Expand All @@ -49,6 +50,9 @@ data class ConversationV1(
override fun onMessage(message: FfiEnvelope) {
trySend(decode(envelope = envelopeFromFFi(message)))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic.description), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down Expand Up @@ -283,6 +287,9 @@ data class ConversationV1(
override fun onMessage(message: FfiEnvelope) {
trySend(envelopeFromFFi(message))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(ephemeralTopic), streamCallback)
awaitClose { launch { stream.end() } }
Expand All @@ -293,6 +300,9 @@ data class ConversationV1(
override fun onMessage(message: FfiEnvelope) {
trySend(decrypt(envelope = envelopeFromFFi(message)))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic.description), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/org/xmtp/android/library/ConversationV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.contents.Invitation
import uniffi.xmtpv3.FfiEnvelope
import uniffi.xmtpv3.FfiV2SubscriptionCallback
import uniffi.xmtpv3.GenericException
import java.util.Date

data class ConversationV2(
Expand Down Expand Up @@ -149,6 +150,9 @@ data class ConversationV2(
trySend(it)
}
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down Expand Up @@ -284,6 +288,9 @@ data class ConversationV2(
override fun onMessage(message: FfiEnvelope) {
trySend(Util.envelopeFromFFi(message))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(ephemeralTopic), streamCallback)
awaitClose { launch { stream.end() } }
Expand All @@ -294,6 +301,9 @@ data class ConversationV2(
override fun onMessage(message: FfiEnvelope) {
trySend(decrypt(envelope = Util.envelopeFromFFi(message)))
}

override fun onError(error: GenericException) {
}
}
val stream = client.subscribe(listOf(topic), streamCallback)
awaitClose { launch { stream.end() } }
Expand Down
26 changes: 20 additions & 6 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.xmtp.proto.message.contents.Contact
import org.xmtp.proto.message.contents.Invitation
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 All @@ -53,6 +54,7 @@ import uniffi.xmtpv3.FfiSubscribeException
import uniffi.xmtpv3.FfiV2SubscribeRequest
import uniffi.xmtpv3.FfiV2Subscription
import uniffi.xmtpv3.FfiV2SubscriptionCallback
import uniffi.xmtpv3.GenericException
import uniffi.xmtpv3.NoPointer
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionPolicySet
Expand All @@ -78,7 +80,7 @@ data class Conversations(
suspend fun conversationFromWelcome(envelopeBytes: ByteArray): Conversation {
val conversation = libXMTPConversations?.processStreamedWelcomeMessage(envelopeBytes)
?: throw XMTPException("Client does not support Groups")
if (conversation.groupMetadata().conversationType() == "dm") {
if (conversation.conversationType() == FfiConversationType.DM) {
return Conversation.Dm(Dm(client, conversation))
} else {
return Conversation.Group(Group(client, conversation))
Expand Down Expand Up @@ -312,7 +314,8 @@ data class Conversations(
opts = FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit?.toLong()
limit?.toLong(),
null
)
) ?: throw XMTPException("Client does not support V3 dms")

Expand All @@ -331,7 +334,8 @@ data class Conversations(
opts = FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit?.toLong()
limit?.toLong(),
null
)
) ?: throw XMTPException("Client does not support V3 dms")

Expand All @@ -354,7 +358,8 @@ data class Conversations(
FfiListConversationsOptions(
after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
before?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS),
limit?.toLong()
limit?.toLong(),
null
)
) ?: throw XMTPException("Client does not support V3 dms")

Expand Down Expand Up @@ -404,7 +409,7 @@ data class Conversations(
}

private fun FfiConversation.toConversation(): Conversation {
return if (groupMetadata().conversationType() == "dm") {
return if (conversationType() == FfiConversationType.DM) {
Conversation.Dm(Dm(client, this))
} else {
Conversation.Group(Group(client, this))
Expand Down Expand Up @@ -533,6 +538,9 @@ data class Conversations(
}
}
}

override fun onError(error: GenericException) {
}
}

val stream = client.subscribe2(
Expand All @@ -556,7 +564,7 @@ data class Conversations(
if (client.hasV2Client) throw XMTPException("Only supported for V3 only clients.")
val conversationCallback = object : FfiConversationCallback {
override fun onConversation(conversation: FfiConversation) {
if (conversation.groupMetadata().conversationType() == "dm") {
if (conversation.conversationType() == FfiConversationType.DM) {
trySend(Conversation.Dm(Dm(client, conversation)))
} else {
trySend(Conversation.Group(Group(client, conversation)))
Expand Down Expand Up @@ -963,6 +971,9 @@ data class Conversations(
else -> {}
}
}

override fun onError(error: GenericException) {
}
}

stream = client.subscribe2(subscriptionRequest, subscriptionCallback)
Expand Down Expand Up @@ -1013,6 +1024,9 @@ data class Conversations(
else -> {}
}
}

override fun onError(error: GenericException) {
}
}

stream = client.subscribe2(subscriptionRequest, subscriptionCallback)
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 701839e

Please sign in to comment.