Skip to content

Commit

Permalink
Update optimistic sending to be cleaner (#272)
Browse files Browse the repository at this point in the history
* update optimistic sending so it works more correctly

* fix lint issue
  • Loading branch information
nplasterer authored Jul 9, 2024
1 parent 4d7e05c commit 3272933
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -871,14 +871,14 @@ class GroupTest {
runBlocking { alixClient.conversations.syncGroups() }
val alixGroup: Group = alixClient.findGroup(boGroup.id)!!
assert(!alixClient.contacts.isGroupAllowed(boGroup.id))
val preparedMessage = runBlocking { alixGroup.prepareMessage("Test text") }
val preparedMessageId = runBlocking { alixGroup.prepareMessage("Test text") }
assert(alixClient.contacts.isGroupAllowed(boGroup.id))
assertEquals(alixGroup.messages().size, 1)
assertEquals(alixGroup.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 0)
assertEquals(alixGroup.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 1)

runBlocking {
preparedMessage.publish()
alixGroup.publishMessages()
alixGroup.sync()
}

Expand All @@ -888,6 +888,6 @@ class GroupTest {

val message = alixGroup.messages().first()

assertEquals(preparedMessage.messageId, message.id)
assertEquals(preparedMessageId, message.id)
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: d4d8134a
Version: ec1da4e6
Branch: main
Date: 2024-07-08 15:44:32 +0000
Date: 2024-07-09 15:32:56 +0000
9 changes: 6 additions & 3 deletions library/src/main/java/org/xmtp/android/library/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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 uniffi.xmtpv3.org.xmtp.android.library.libxmtp.UnpublishedMessage
import java.util.Date
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.DurationUnit
Expand Down Expand Up @@ -100,12 +99,16 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) {
return encoded
}

suspend fun <T> prepareMessage(content: T, options: SendOptions? = null): UnpublishedMessage {
suspend fun <T> prepareMessage(content: T, options: SendOptions? = null): String {
if (client.contacts.consentList.groupState(groupId = id) == ConsentState.UNKNOWN) {
client.contacts.allowGroups(groupIds = listOf(id))
}
val encodeContent = encodeContent(content = content, options = options)
return UnpublishedMessage(libXMTPGroup.sendOptimistic(encodeContent.toByteArray()))
return libXMTPGroup.sendOptimistic(encodeContent.toByteArray()).toHex()
}

suspend fun publishMessages() {
libXMTPGroup.publishMessages()
}

suspend fun sync() {
Expand Down

This file was deleted.

Loading

0 comments on commit 3272933

Please sign in to comment.