From 17f210baf4493a7a8fb65104f845a4ee3d84034b Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Tue, 16 Jan 2024 18:03:14 -0300 Subject: [PATCH 1/6] fix: update ConversationV2 createdAt property --- .../xmtp/android/library/ConversationsTest.kt | 77 +++++++++++++++++++ .../org/xmtp/android/library/Conversation.kt | 2 +- .../xmtp/android/library/ConversationV2.kt | 4 +- .../org/xmtp/android/library/Conversations.kt | 1 + 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt index e516281d2..004d21210 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt @@ -20,6 +20,7 @@ import org.xmtp.android.library.messages.createDeterministic import org.xmtp.android.library.messages.getPublicKeyBundle import org.xmtp.android.library.messages.toPublicKeyBundle import org.xmtp.android.library.messages.walletAddress +import org.xmtp.proto.keystore.api.v1.Keystore import java.lang.Thread.sleep import java.util.Date @@ -137,4 +138,80 @@ class ConversationsTest { assertEquals(allMessages.size, 15) } + + @Test + fun testLoadConvos() { + // Build from [8,54,32,15,250,250,23,163,203,139,84,242,45,106,250,96,177,61,164,135,38,84,50,65,173,197,194,80,219,176,224,205] + // or in hex 0836200ffafa17a3cb8b54f22d6afa60b13da48726543241adc5c250dbb0e0cd + // aka 2k many convos test wallet + // Create a ByteArray with the 32 bytes above + val privateKeyData = listOf( + 0x08, + 0x36, + 0x20, + 0x0f, + 0xfa, + 0xfa, + 0x17, + 0xa3, + 0xcb, + 0x8b, + 0x54, + 0xf2, + 0x2d, + 0x6a, + 0xfa, + 0x60, + 0xb1, + 0x3d, + 0xa4, + 0x87, + 0x26, + 0x54, + 0x32, + 0x41, + 0xad, + 0xc5, + 0xc2, + 0x50, + 0xdb, + 0xb0, + 0xe0, + 0xcd + ) + .map { it.toByte() } + .toByteArray() + // Use hardcoded privateKey + val privateKey = PrivateKeyBuilder.buildFromPrivateKeyData(privateKeyData) + val privateKeyBuilder = PrivateKeyBuilder(privateKey) + val options = + ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.DEV)) + val client = Client().create(account = privateKeyBuilder, options = options) + + val start = Date() + val conversations = client.conversations.list() + val end = Date() + println("Loaded ${conversations.size} conversations in ${(end.time - start.time) / 1000.0}s") + + val start2 = Date() + val conversations2 = client.conversations.list() + val end2 = Date() + println("Second time loaded ${conversations2.size} conversations in ${(end2.time - start2.time) / 1000.0}s") + + val last500Topics = conversations.takeLast(500).map { it.toTopicData().toByteString() } + val client2 = Client().create(account = privateKeyBuilder, options = options) + for (topic in last500Topics) { + client2.conversations.importTopicData(Keystore.TopicMap.TopicData.parseFrom(topic)) + } + + val start3 = Date() + val conversations3 = client2.conversations.list() + val end3 = Date() + println("Loaded ${conversations3.size} conversations in ${(end3.time - start3.time) / 1000.0}s") + + val start4 = Date() + val conversations4 = client2.conversations.list() + val end4 = Date() + println("Second time loaded ${conversations4.size} conversations in ${(end4.time - start4.time) / 1000.0}s") + } } diff --git a/library/src/main/java/org/xmtp/android/library/Conversation.kt b/library/src/main/java/org/xmtp/android/library/Conversation.kt index 9a5382f6b..32f9b6642 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversation.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversation.kt @@ -40,7 +40,7 @@ sealed class Conversation { get() { return when (this) { is V1 -> conversationV1.sentAt - is V2 -> conversationV2.createdAt + is V2 -> conversationV2.conversationCreatedAt } } 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 3f6e610e4..c70479d60 100644 --- a/library/src/main/java/org/xmtp/android/library/ConversationV2.kt +++ b/library/src/main/java/org/xmtp/android/library/ConversationV2.kt @@ -30,6 +30,7 @@ data class ConversationV2( val context: Invitation.InvitationV1.Context, val peerAddress: String, val client: Client, + val createdAt: Long? = null, private val header: SealedInvitationHeaderV1, ) { @@ -50,12 +51,13 @@ data class ConversationV2( context = invitation.context, peerAddress = peerAddress, client = client, + createdAt = header.createdNs, header = header, ) } } - val createdAt: Date = Date(header.createdNs / 1_000_000) + val conversationCreatedAt: Date = Date((createdAt ?: 0L) / 1_000_000) /** * This lists messages sent to the [Conversation]. 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 51c897026..5c0029765 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversations.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversations.kt @@ -226,6 +226,7 @@ data class Conversations( context = data.invitation.context, peerAddress = data.peerAddress, client = client, + createdAt = data.createdNs, header = Invitation.SealedInvitationHeaderV1.getDefaultInstance(), ), ) From 30274dbf041b7ca0c4f6743efca5437ecb5e1b0f Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Wed, 17 Jan 2024 12:01:42 -0300 Subject: [PATCH 2/6] remove test --- .../xmtp/android/library/ConversationsTest.kt | 78 +------------------ 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt index 004d21210..b5bfb47e5 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt @@ -138,80 +138,4 @@ class ConversationsTest { assertEquals(allMessages.size, 15) } - - @Test - fun testLoadConvos() { - // Build from [8,54,32,15,250,250,23,163,203,139,84,242,45,106,250,96,177,61,164,135,38,84,50,65,173,197,194,80,219,176,224,205] - // or in hex 0836200ffafa17a3cb8b54f22d6afa60b13da48726543241adc5c250dbb0e0cd - // aka 2k many convos test wallet - // Create a ByteArray with the 32 bytes above - val privateKeyData = listOf( - 0x08, - 0x36, - 0x20, - 0x0f, - 0xfa, - 0xfa, - 0x17, - 0xa3, - 0xcb, - 0x8b, - 0x54, - 0xf2, - 0x2d, - 0x6a, - 0xfa, - 0x60, - 0xb1, - 0x3d, - 0xa4, - 0x87, - 0x26, - 0x54, - 0x32, - 0x41, - 0xad, - 0xc5, - 0xc2, - 0x50, - 0xdb, - 0xb0, - 0xe0, - 0xcd - ) - .map { it.toByte() } - .toByteArray() - // Use hardcoded privateKey - val privateKey = PrivateKeyBuilder.buildFromPrivateKeyData(privateKeyData) - val privateKeyBuilder = PrivateKeyBuilder(privateKey) - val options = - ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.DEV)) - val client = Client().create(account = privateKeyBuilder, options = options) - - val start = Date() - val conversations = client.conversations.list() - val end = Date() - println("Loaded ${conversations.size} conversations in ${(end.time - start.time) / 1000.0}s") - - val start2 = Date() - val conversations2 = client.conversations.list() - val end2 = Date() - println("Second time loaded ${conversations2.size} conversations in ${(end2.time - start2.time) / 1000.0}s") - - val last500Topics = conversations.takeLast(500).map { it.toTopicData().toByteString() } - val client2 = Client().create(account = privateKeyBuilder, options = options) - for (topic in last500Topics) { - client2.conversations.importTopicData(Keystore.TopicMap.TopicData.parseFrom(topic)) - } - - val start3 = Date() - val conversations3 = client2.conversations.list() - val end3 = Date() - println("Loaded ${conversations3.size} conversations in ${(end3.time - start3.time) / 1000.0}s") - - val start4 = Date() - val conversations4 = client2.conversations.list() - val end4 = Date() - println("Second time loaded ${conversations4.size} conversations in ${(end4.time - start4.time) / 1000.0}s") - } -} +} \ No newline at end of file From 1096d9d34806b7dd7374049429a81d69140b07e7 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Wed, 17 Jan 2024 12:06:39 -0300 Subject: [PATCH 3/6] resolve comments --- .../src/main/java/org/xmtp/android/library/Conversation.kt | 2 +- .../main/java/org/xmtp/android/library/ConversationV2.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/org/xmtp/android/library/Conversation.kt b/library/src/main/java/org/xmtp/android/library/Conversation.kt index 32f9b6642..9a5382f6b 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversation.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversation.kt @@ -40,7 +40,7 @@ sealed class Conversation { get() { return when (this) { is V1 -> conversationV1.sentAt - is V2 -> conversationV2.conversationCreatedAt + is V2 -> conversationV2.createdAt } } 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 c70479d60..6d20253c6 100644 --- a/library/src/main/java/org/xmtp/android/library/ConversationV2.kt +++ b/library/src/main/java/org/xmtp/android/library/ConversationV2.kt @@ -30,7 +30,7 @@ data class ConversationV2( val context: Invitation.InvitationV1.Context, val peerAddress: String, val client: Client, - val createdAt: Long? = null, + val createdAtNs: Long? = null, private val header: SealedInvitationHeaderV1, ) { @@ -51,13 +51,13 @@ data class ConversationV2( context = invitation.context, peerAddress = peerAddress, client = client, - createdAt = header.createdNs, + createdAtNs = header.createdNs, header = header, ) } } - val conversationCreatedAt: Date = Date((createdAt ?: 0L) / 1_000_000) + val createdAt: Date = Date((createdAtNs ?: header.createdNs) / 1_000_000) /** * This lists messages sent to the [Conversation]. From 045e16070c46176511bfa84e94320098026ab60c Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Wed, 17 Jan 2024 12:11:58 -0300 Subject: [PATCH 4/6] Remove unused import statement --- .../java/org/xmtp/android/library/ConversationsTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt index b5bfb47e5..48603d36b 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt @@ -20,7 +20,6 @@ import org.xmtp.android.library.messages.createDeterministic import org.xmtp.android.library.messages.getPublicKeyBundle import org.xmtp.android.library.messages.toPublicKeyBundle import org.xmtp.android.library.messages.walletAddress -import org.xmtp.proto.keystore.api.v1.Keystore import java.lang.Thread.sleep import java.util.Date From 6f35842fc613f011e85cf3b513a41fc08b3a029b Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Wed, 17 Jan 2024 12:20:26 -0300 Subject: [PATCH 5/6] fix lint issue --- .../java/org/xmtp/android/library/ConversationsTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt index 48603d36b..e516281d2 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt @@ -137,4 +137,4 @@ class ConversationsTest { assertEquals(allMessages.size, 15) } -} \ No newline at end of file +} From 54f5df77338d3ba8a7ae440461ade73f324557e9 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Wed, 17 Jan 2024 12:27:01 -0300 Subject: [PATCH 6/6] Fix createdAt field name in Conversations data class --- library/src/main/java/org/xmtp/android/library/Conversations.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5c0029765..71edc7b37 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversations.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversations.kt @@ -226,7 +226,7 @@ data class Conversations( context = data.invitation.context, peerAddress = data.peerAddress, client = client, - createdAt = data.createdNs, + createdAtNs = data.createdNs, header = Invitation.SealedInvitationHeaderV1.getDefaultInstance(), ), )