Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update consent syncing and removes group update message from dms #326

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class AttachmentTest {
)
}
val messages = runBlocking { aliceConversation.messages() }
assertEquals(messages.size, 2)
if (messages.size == 2) {
assertEquals(messages.size, 1)
if (messages.size == 1) {
val content: Attachment? = messages[0].content()
assertEquals("test.txt", content?.filename)
assertEquals("text/plain", content?.mimeType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class CodecTest {
)
}
val messages = runBlocking { aliceConversation.messages() }
assertEquals(messages.size, 2)
if (messages.size == 2) {
assertEquals(messages.size, 1)
if (messages.size == 1) {
val content: Double? = messages[0].content()
assertEquals(3.14, content)
assertEquals("Error: This app does not support numbers.", messages[0].fallbackContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,15 @@ class ConversationsTest {
runBlocking {
boClient.conversations.sync()
boDm?.sync()
alixClient.conversations.sync()
alixClient2.conversations.sync()
val dm2 = alixClient2.findConversation(dm.id)!!
alixClient2.syncConsent()
assertEquals(dm2.consentState(), ConsentState.DENIED)
alixClient.conversations.syncAllConversations()
Thread.sleep(2000)
alixClient2.conversations.syncAllConversations()
Thread.sleep(2000)
val dm2 = alixClient2.findConversation(dm.id)!!
assertEquals(ConsentState.DENIED, dm2.consentState())
alixClient2.preferences.consentList.setConsentState(
listOf(
ConsentListEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
Expand All @@ -215,12 +215,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.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
Expand Down Expand Up @@ -253,7 +253,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
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ class GroupTest {

assertEquals(alixGroup.messages().size, 1)
assertEquals(alixGroup2.messages().size, 1)
assertEquals(numGroups, 2u)
assertEquals(numGroups, 3u)

runBlocking {
boGroup2.removeMembers(listOf(alix.walletAddress))
Expand All @@ -933,17 +933,18 @@ class GroupTest {
boGroup2.send("hi")
boGroup2.send("hi")
numGroups = alixClient.conversations.syncAllConversations()
Thread.sleep(2000)
}

assertEquals(alixGroup.messages().size, 3)
assertEquals(alixGroup2.messages().size, 2)
// First syncAllGroups after remove includes the group you're removed from
assertEquals(numGroups, 2u)
assertEquals(numGroups, 3u)

runBlocking {
numGroups = alixClient.conversations.syncAllConversations()
}
// Next syncAllGroups will not include the inactive group
assertEquals(numGroups, 1u)
assertEquals(numGroups, 2u)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class ReactionTest {
)
}
val messages = runBlocking { aliceConversation.messages() }
assertEquals(messages.size, 3)
if (messages.size == 3) {
assertEquals(messages.size, 2)
if (messages.size == 2) {
val content: Reaction? = messages.first().content()
assertEquals("U+1F603", content?.content)
assertEquals(messageToReact.id, content?.reference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class ReadReceiptTest {
)
}
val messages = runBlocking { aliceConversation.messages() }
assertEquals(messages.size, 3)
if (messages.size == 3) {
assertEquals(messages.size, 2)
if (messages.size == 2) {
val contentType: String = messages.first().encodedContent.type.typeId
assertEquals(contentType, "readReceipt")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ReplyTest {
)
}
val messages = runBlocking { aliceConversation.messages() }
assertEquals(messages.size, 3)
if (messages.size == 3) {
assertEquals(messages.size, 2)
if (messages.size == 2) {
val content: Reply? = messages.first().content()
assertEquals("Hello", content?.content)
assertEquals(messageToReact.id, content?.reference)
Expand Down
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: ae7a267d
Version: 29a955a1
Branch: main
Date: 2024-11-07 20:55:17 +0000
Date: 2024-11-14 22:21:21 +0000
31 changes: 14 additions & 17 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 All @@ -25,7 +26,7 @@ data class ClientOptions(
val dbEncryptionKey: ByteArray,
val historySyncUrl: String = when (api.env) {
XMTPEnvironment.PRODUCTION -> "https://message-history.production.ephemera.network/"
XMTPEnvironment.LOCAL -> "http://0.0.0.0:5558"
XMTPEnvironment.LOCAL -> "http://10.0.2.2:5558"
else -> "https://message-history.dev.ephemera.network/"
},
val dbDirectory: String? = null,
Expand Down Expand Up @@ -63,10 +64,10 @@ class Client() {
logger = XMTPLogger(),
host = environment.env.getUrl(),
isSecure = environment.isSecure,
accountAddress = address
accountAddress = address.lowercase()
)
if (inboxId.isNullOrBlank()) {
inboxId = generateInboxId(address, 0.toULong())
inboxId = generateInboxId(address.lowercase(), 0.toULong())
}
return inboxId
}
Expand All @@ -84,7 +85,7 @@ class Client() {
inboxId: String,
environment: XMTPEnvironment,
) : this() {
this.address = address
this.address = address.lowercase()
this.preferences = PrivatePreferences(client = this, ffiClient = libXMTPClient)
this.ffiClient = libXMTPClient
this.conversations =
Expand Down Expand Up @@ -169,7 +170,7 @@ class Client() {
isSecure = options.api.isSecure,
db = dbPath,
encryptionKey = options.dbEncryptionKey,
accountAddress = accountAddress,
accountAddress = accountAddress.lowercase(),
inboxId = inboxId,
nonce = 0.toULong(),
legacySignedPrivateKeyProto = null,
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
Loading
Loading