Skip to content

Commit

Permalink
fix: update ConversationV2 createdAt property
Browse files Browse the repository at this point in the history
  • Loading branch information
kele-leanes committed Jan 16, 2024
1 parent 943314a commit 17f210b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sealed class Conversation {
get() {
return when (this) {
is V1 -> conversationV1.sentAt
is V2 -> conversationV2.createdAt
is V2 -> conversationV2.conversationCreatedAt
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {

Expand All @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ data class Conversations(
context = data.invitation.context,
peerAddress = data.peerAddress,
client = client,
createdAt = data.createdNs,
header = Invitation.SealedInvitationHeaderV1.getDefaultInstance(),
),
)
Expand Down

0 comments on commit 17f210b

Please sign in to comment.