From 01898a78baf740e91d90ada8fff9ef6d4239a0e4 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 14 Nov 2024 07:39:50 -0800 Subject: [PATCH] Revert "Dual Send 1to1 Conversations in V3 (#306)" This reverts commit bded2b73022822572d2cda3aafe976fbe3ea9e12. --- .../org/xmtp/android/library/GroupTest.kt | 40 ------------------- .../xmtp/android/library/ConversationV1.kt | 12 +----- .../xmtp/android/library/ConversationV2.kt | 12 +----- .../org/xmtp/android/library/Conversations.kt | 15 +++---- .../xmtp/android/library/PreparedMessage.kt | 4 +- 5 files changed, 11 insertions(+), 72 deletions(-) diff --git a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt index 3b3d23a1b..7fb5a8952 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt @@ -75,46 +75,6 @@ class GroupTest { runBlocking { Client().createV3(account = davonV3Wallet, options = options) } } - @Test - fun testsCanDualSendConversations() { - val v2Convo = runBlocking { alixClient.conversations.newConversation(bo.walletAddress) } - runBlocking { - alixClient.conversations.syncConversations() - boClient.conversations.syncConversations() - } - val alixDm = runBlocking { alixClient.findDm(bo.walletAddress) } - val boDm = runBlocking { boClient.findDm(alix.walletAddress) } - - assertEquals(alixDm?.id, boDm?.id) - assertEquals(runBlocking { alixClient.conversations.list().size }, 1) - assertEquals(runBlocking { alixClient.conversations.listDms().size }, 1) - assertEquals(runBlocking { boClient.conversations.listDms().size }, 1) - assertEquals(runBlocking { boClient.conversations.list().size }, 1) - assertEquals(v2Convo.topic, runBlocking { boClient.conversations.list().first().topic }) - } - - @Test - fun testsCanDualSendMessages() { - val alixV2Convo = runBlocking { alixClient.conversations.newConversation(bo.walletAddress) } - val boV2Convo = runBlocking { boClient.conversations.list().first() } - runBlocking { boClient.conversations.syncConversations() } - val alixDm = runBlocking { alixClient.findDm(bo.walletAddress) } - val boDm = runBlocking { boClient.findDm(alix.walletAddress) } - - runBlocking { alixV2Convo.send("first") } - runBlocking { boV2Convo.send("second") } - - runBlocking { - alixDm?.sync() - boDm?.sync() - } - - assertEquals(runBlocking { alixV2Convo.messages().size }, 2) - assertEquals(runBlocking { alixV2Convo.messages().size }, runBlocking { boV2Convo.messages().size }) - assertEquals(boDm?.messages()?.size, 2) - assertEquals(alixDm?.messages()?.size, 3) // We send the group membership update to the dm - } - @Test fun testCanCreateAGroupWithDefaultPermissions() { val boGroup = runBlocking { diff --git a/library/src/main/java/org/xmtp/android/library/ConversationV1.kt b/library/src/main/java/org/xmtp/android/library/ConversationV1.kt index ef0cf66d2..2d031b5fe 100644 --- a/library/src/main/java/org/xmtp/android/library/ConversationV1.kt +++ b/library/src/main/java/org/xmtp/android/library/ConversationV1.kt @@ -195,16 +195,6 @@ data class ConversationV1( } suspend fun send(prepared: PreparedMessage): String { - if (client.v3Client != null) { - try { - val dm = client.conversations.findOrCreateDm(peerAddress) - prepared.encodedContent?.let { - dm.send(it) - } - } catch (e: Exception) { - Log.e("ConversationV1 send", e.message.toString()) - } - } client.publish(envelopes = prepared.envelopes) if (client.contacts.consentList.state(address = peerAddress) == ConsentState.UNKNOWN) { client.contacts.allow(addresses = listOf(peerAddress)) @@ -279,7 +269,7 @@ data class ConversationV1( ) client.contacts.hasIntroduced[peerAddress] = true } - return PreparedMessage(envelopes, encodedContent) + return PreparedMessage(envelopes) } private fun generateId(envelope: Envelope): String = diff --git a/library/src/main/java/org/xmtp/android/library/ConversationV2.kt b/library/src/main/java/org/xmtp/android/library/ConversationV2.kt index 90a1b80d0..981934d8f 100644 --- a/library/src/main/java/org/xmtp/android/library/ConversationV2.kt +++ b/library/src/main/java/org/xmtp/android/library/ConversationV2.kt @@ -200,16 +200,6 @@ data class ConversationV2( } suspend fun send(prepared: PreparedMessage): String { - if (client.v3Client != null) { - try { - val dm = client.conversations.findOrCreateDm(peerAddress) - prepared.encodedContent?.let { - dm.send(it) - } - } catch (e: Exception) { - Log.e("ConversationV1 send", e.message.toString()) - } - } client.publish(envelopes = prepared.envelopes) if (client.contacts.consentList.state(address = peerAddress) == ConsentState.UNKNOWN) { client.contacts.allow(addresses = listOf(peerAddress)) @@ -280,7 +270,7 @@ data class ConversationV2( timestamp = Date(), message = MessageBuilder.buildFromMessageV2(v2 = message.messageV2).toByteArray(), ) - return PreparedMessage(listOf(envelope), encodedContent) + return PreparedMessage(listOf(envelope)) } private fun generateId(envelope: Envelope): String = diff --git a/library/src/main/java/org/xmtp/android/library/Conversations.kt b/library/src/main/java/org/xmtp/android/library/Conversations.kt index 8c9b65dcd..a346cc710 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversations.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversations.kt @@ -193,6 +193,7 @@ data class Conversations( } suspend fun findOrCreateDm(peerAddress: String): Dm { + if (client.hasV2Client) throw XMTPException("Only supported for V3 only clients.") if (peerAddress.lowercase() == client.address.lowercase()) { throw XMTPException("Recipient is sender") } @@ -299,13 +300,6 @@ data class Conversations( client.contacts.allow(addresses = listOf(peerAddress)) val conversation = Conversation.V2(conversationV2) conversationsByTopic[conversation.topic] = conversation - if (client.v3Client != null) { - try { - client.conversations.findOrCreateDm(peerAddress) - } catch (e: Exception) { - Log.e("newConversation", e.message.toString()) - } - } return conversation } @@ -332,6 +326,7 @@ data class Conversations( before: Date? = null, limit: Int? = null, ): List { + if (client.hasV2Client) throw XMTPException("Only supported for V3 only clients.") val ffiDms = libXMTPConversations?.listDms( opts = FfiListConversationsOptions( after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS), @@ -352,6 +347,9 @@ data class Conversations( order: ConversationOrder = ConversationOrder.CREATED_AT, consentState: ConsentState? = null, ): List { + if (client.hasV2Client) + throw XMTPException("Only supported for V3 only clients.") + val ffiConversations = libXMTPConversations?.list( FfiListConversationsOptions( after?.time?.nanoseconds?.toLong(DurationUnit.NANOSECONDS), @@ -555,6 +553,7 @@ data class Conversations( } fun streamConversations(): Flow = callbackFlow { + 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") { @@ -657,6 +656,7 @@ data class Conversations( } fun streamAllConversationMessages(): Flow = callbackFlow { + if (client.hasV2Client) throw XMTPException("Only supported for V3 only clients.") val messageCallback = object : FfiMessageCallback { override fun onMessage(message: FfiMessage) { val conversation = client.findConversation(message.convoId.toHex()) @@ -684,6 +684,7 @@ data class Conversations( } fun streamAllConversationDecryptedMessages(): Flow = callbackFlow { + if (client.hasV2Client) throw XMTPException("Only supported for V3 only clients.") val messageCallback = object : FfiMessageCallback { override fun onMessage(message: FfiMessage) { val conversation = client.findConversation(message.convoId.toHex()) diff --git a/library/src/main/java/org/xmtp/android/library/PreparedMessage.kt b/library/src/main/java/org/xmtp/android/library/PreparedMessage.kt index e2f762dd1..6bfc2cf48 100644 --- a/library/src/main/java/org/xmtp/android/library/PreparedMessage.kt +++ b/library/src/main/java/org/xmtp/android/library/PreparedMessage.kt @@ -3,7 +3,6 @@ package org.xmtp.android.library import org.web3j.crypto.Hash import org.xmtp.android.library.messages.Envelope import org.xmtp.proto.message.api.v1.MessageApiOuterClass.PublishRequest -import org.xmtp.proto.message.contents.Content.EncodedContent // This houses a fully prepared message that can be published // as soon as the API client has connectivity. @@ -15,8 +14,7 @@ data class PreparedMessage( // The first envelope should send the message to the conversation itself. // Any more are for required intros/invites etc. // A client can just publish these when it has connectivity. - val envelopes: List, - val encodedContent: EncodedContent? = null + val envelopes: List ) { companion object { fun fromSerializedData(data: ByteArray): PreparedMessage {