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

[V3] Remove Decrypted Messages #313

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -4,21 +4,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.protobuf.kotlin.toByteStringUtf8
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.Crypto.Companion.verifyHmacSignature
import org.xmtp.android.library.codecs.ContentCodec
import org.xmtp.android.library.codecs.ContentTypeId
import org.xmtp.android.library.codecs.ContentTypeIdBuilder
import org.xmtp.android.library.codecs.EncodedContent
import org.xmtp.android.library.codecs.TextCodec
import org.xmtp.android.library.messages.InvitationV1ContextBuilder
import org.xmtp.android.library.messages.MessageV2Builder
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
import java.time.Instant

data class NumberCodec(
override var contentType: ContentTypeId = ContentTypeIdBuilder.builderFromAuthorityId(
Expand Down
53 changes: 1 addition & 52 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionAction
import org.xmtp.android.library.codecs.ReactionCodec
import org.xmtp.android.library.codecs.ReactionSchema
import org.xmtp.android.library.messages.DecryptedMessage
import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.libxmtp.Message.*
import org.xmtp.android.library.messages.PrivateKey
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
Expand Down Expand Up @@ -277,56 +276,6 @@ class DmTest {
job.cancel()
}

@Test
fun testCanStreamDecryptedDmMessages() = kotlinx.coroutines.test.runTest {
val dm = boClient.conversations.findOrCreateDm(alix.walletAddress)
alixClient.conversations.syncConversations()
val alixDm = alixClient.findDm(bo.walletAddress)
dm.streamDecryptedMessages().test {
alixDm?.send("hi")
assertEquals("hi", awaitItem().encodedContent.content.toStringUtf8())
alixDm?.send("hi again")
assertEquals("hi again", awaitItem().encodedContent.content.toStringUtf8())
}
}

@Test
fun testCanStreamAllDecryptedDmMessages() {
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
runBlocking { alixClient.conversations.syncConversations() }

val allMessages = mutableListOf<DecryptedMessage>()

val job = CoroutineScope(Dispatchers.IO).launch {
try {
alixClient.conversations.streamAllDecryptedMessages().collect { message ->
allMessages.add(message)
}
} catch (e: Exception) {
}
}
Thread.sleep(2500)

for (i in 0 until 2) {
runBlocking { dm.send(text = "Message $i") }
Thread.sleep(100)
}
assertEquals(2, allMessages.size)

val caroDm =
runBlocking { caroClient.conversations.findOrCreateDm(alixClient.address) }
Thread.sleep(2500)

for (i in 0 until 2) {
runBlocking { caroDm.send(text = "Message $i") }
Thread.sleep(100)
}

assertEquals(4, allMessages.size)

job.cancel()
}

@Test
fun testCanStreamConversations() = kotlinx.coroutines.test.runTest {
boClient.conversations.stream().test {
Expand Down
97 changes: 5 additions & 92 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionAction
import org.xmtp.android.library.codecs.ReactionCodec
import org.xmtp.android.library.codecs.ReactionSchema
import org.xmtp.android.library.messages.DecryptedMessage
import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.libxmtp.Message.*
import org.xmtp.android.library.messages.PrivateKey
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
Expand Down Expand Up @@ -336,13 +335,13 @@ class GroupTest {
fun testMessageTimeIsCorrect() {
val alixGroup = runBlocking { alixClient.conversations.newGroup(listOf(boClient.address)) }
runBlocking { alixGroup.send("Hello") }
assertEquals(alixGroup.decryptedMessages().size, 2)
assertEquals(alixGroup.messages().size, 2)
runBlocking { alixGroup.sync() }
val message2 = alixGroup.decryptedMessages().last()
val message2 = alixGroup.messages().last()
runBlocking { alixGroup.sync() }
val message3 = alixGroup.decryptedMessages().last()
val message3 = alixGroup.messages().last()
assertEquals(message3.id, message2.id)
assertEquals(message3.sentAt.time, message2.sentAt.time)
assertEquals(message3.sent.time, message2.sent.time)
}

@Test
Expand Down Expand Up @@ -665,92 +664,6 @@ class GroupTest {
job.cancel()
}

@Test
fun testCanStreamDecryptedGroupMessages() = kotlinx.coroutines.test.runTest {
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
alixClient.conversations.syncConversations()
val alixGroup = alixClient.conversations.listGroups().first()
group.streamDecryptedMessages().test {
alixGroup.send("hi")
assertEquals("hi", awaitItem().encodedContent.content.toStringUtf8())
alixGroup.send("hi again")
assertEquals("hi again", awaitItem().encodedContent.content.toStringUtf8())
}
}

@Test
fun testCanStreamAllDecryptedGroupMessages() {
val group = runBlocking { caroClient.conversations.newGroup(listOf(alix.walletAddress)) }
val dm = runBlocking { davonV3Client.conversations.findOrCreateDm(alix.walletAddress) }
runBlocking { alixClient.conversations.syncConversations() }

val allMessages = mutableListOf<DecryptedMessage>()

val job = CoroutineScope(Dispatchers.IO).launch {
try {
alixClient.conversations.streamAllDecryptedMessages().collect { message ->
allMessages.add(message)
}
} catch (e: Exception) {
}
}
Thread.sleep(2500)

runBlocking { dm.send("Should not stream") }
for (i in 0 until 2) {
runBlocking { group.send(text = "Message $i") }
Thread.sleep(100)
}
assertEquals(2, allMessages.size)

val caroGroup =
runBlocking { caroClient.conversations.newGroup(listOf(alixClient.address)) }
Thread.sleep(2500)

for (i in 0 until 2) {
runBlocking { caroGroup.send(text = "Message $i") }
Thread.sleep(100)
}

assertEquals(4, allMessages.size)

job.cancel()
}

@Test
fun testCanStreamAllDecryptedMessages() {
val group = runBlocking { caroClient.conversations.newGroup(listOf(alix.walletAddress)) }
val dm = runBlocking { davonV3Client.conversations.findOrCreateDm(alix.walletAddress) }
val conversation =
runBlocking { boClient.conversations.newConversation(alix.walletAddress) }
runBlocking { alixClient.conversations.syncConversations() }

val allMessages = mutableListOf<DecryptedMessage>()

val job = CoroutineScope(Dispatchers.IO).launch {
try {
alixClient.conversations.streamAllDecryptedMessages()
.collect { message ->
allMessages.add(message)
}
} catch (e: Exception) {
}
}
Thread.sleep(2500)

runBlocking {
dm.send("should not stream")
group.send("hi")
conversation.send("hi")
}

Thread.sleep(1000)

assertEquals(2, allMessages.size)

job.cancel()
}

@Test
fun testCanStreamGroups() = kotlinx.coroutines.test.runTest {
boClient.conversations.stream().test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.protobuf.kotlin.toByteStringUtf8
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.codecs.ContentTypeReaction
Expand All @@ -13,7 +12,6 @@ import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionAction
import org.xmtp.android.library.codecs.ReactionCodec
import org.xmtp.android.library.codecs.ReactionSchema
import org.xmtp.android.library.messages.MessageV2Builder
import org.xmtp.android.library.messages.walletAddress

@RunWith(AndroidJUnit4::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.junit.Assert.assertEquals
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.libxmtp.Message
import org.xmtp.android.library.messages.PrivateKey
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
Expand Down Expand Up @@ -130,7 +130,7 @@ class SmartContractWalletTest {
runBlocking { boGroup.sync() }
assertEquals(boGroup.messages().first().body, "gm")
assertEquals(boGroup.messages().first().id, messageId)
assertEquals(boGroup.messages().first().deliveryStatus, MessageDeliveryStatus.PUBLISHED)
assertEquals(boGroup.messages().first().deliveryStatus, Message.MessageDeliveryStatus.PUBLISHED)
assertEquals(boGroup.messages().size, 3)

runBlocking { davonSCWClient.conversations.syncConversations() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.messages.DecryptedMessage
import org.xmtp.android.library.messages.MessageDeliveryStatus
import org.xmtp.android.library.libxmtp.Message
import org.xmtp.android.library.libxmtp.Message.*
import org.xmtp.android.library.messages.PrivateKey
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
Expand Down Expand Up @@ -313,35 +313,6 @@ class V3ClientTest {
job.cancel()
}

@Test
fun testCanStreamAllDecryptedMessagesFromV3Users() {
val group =
runBlocking { caroV2V3Client.conversations.newGroup(listOf(boV3.walletAddress)) }
val conversation =
runBlocking { boV3Client.conversations.findOrCreateDm(caroV2V3.walletAddress) }
runBlocking { boV3Client.conversations.syncConversations() }

val allMessages = mutableListOf<DecryptedMessage>()

val job = CoroutineScope(Dispatchers.IO).launch {
try {
boV3Client.conversations.streamAllDecryptedMessages()
.collect { message ->
allMessages.add(message)
}
} catch (e: Exception) {
}
}
Thread.sleep(1000)
runBlocking {
group.send("hi")
conversation.send("hi")
}
Thread.sleep(1000)
assertEquals(2, allMessages.size)
job.cancel()
}

@Test
fun testCanStreamGroupsAndConversationsFromV3Users() {
val allMessages = mutableListOf<String>()
Expand Down
16 changes: 3 additions & 13 deletions library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
package org.xmtp.android.library

import android.content.Context
import android.os.Build
import android.util.Log
import com.google.crypto.tink.subtle.Base64
import com.google.gson.GsonBuilder
import kotlinx.coroutines.runBlocking
import org.web3j.crypto.Keys
import org.web3j.crypto.Keys.toChecksumAddress
import org.xmtp.android.library.codecs.ContentCodec
import org.xmtp.android.library.codecs.TextCodec
import org.xmtp.android.library.libxmtp.MessageV3
import org.xmtp.android.library.libxmtp.Message
import org.xmtp.android.library.libxmtp.XMTPLogger
import org.xmtp.android.library.messages.ContactBundle
import org.xmtp.android.library.messages.EncryptedPrivateKeyBundle
import org.xmtp.android.library.messages.Envelope
import org.xmtp.android.library.messages.EnvelopeBuilder
import org.xmtp.android.library.messages.InvitationV1ContextBuilder
import org.xmtp.android.library.messages.Pagination
import org.xmtp.android.library.messages.PrivateKeyBundle
import org.xmtp.android.library.messages.PrivateKeyBundleBuilder
import org.xmtp.android.library.messages.PrivateKeyBundleV1
import org.xmtp.android.library.messages.PrivateKeyBundleV2
import org.xmtp.android.library.messages.SealedInvitationHeaderV1
import org.xmtp.android.library.messages.Topic
import org.xmtp.android.library.messages.decrypted
import org.xmtp.android.library.messages.encrypted
Expand All @@ -48,12 +43,7 @@ import uniffi.xmtpv3.getInboxIdForAddress
import uniffi.xmtpv3.getVersionInfo
import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.InboxState
import java.io.File
import java.nio.charset.StandardCharsets
import java.text.SimpleDateFormat
import java.time.Instant
import java.util.Date
import java.util.Locale
import java.util.TimeZone

typealias PublishResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.PublishResponse
typealias QueryResponse = org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryResponse
Expand Down Expand Up @@ -640,10 +630,10 @@ class Client() {
}
}

fun findMessage(messageId: String): MessageV3? {
fun findMessage(messageId: String): Message? {
val client = v3Client ?: throw XMTPException("Error no V3 client initialized")
return try {
MessageV3(this, client.message(messageId.hexToByteArray()))
Message(this, client.message(messageId.hexToByteArray()))
} catch (e: Exception) {
null
}
Expand Down
Loading
Loading