Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/xmtp/xmtp-android into np/f…
Browse files Browse the repository at this point in the history
…rames-signer
  • Loading branch information
nplasterer committed Dec 18, 2024
2 parents a8a727f + de8949b commit 8550d9c
Show file tree
Hide file tree
Showing 24 changed files with 662 additions and 218 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ conversation.send(text = "gm")

// Listen for new messages in the conversation
conversation.streamMessages().collect {
print("${it.senderAddress}: ${it.body}")
print("${it.senderInboxId}: ${it.body}")
}
```

Expand Down Expand Up @@ -199,17 +199,17 @@ val nextPage = conversation.messages(limit = 25, beforeNs = messages[0].sentNs)

You can listen for any new messages (incoming or outgoing) in a conversation by calling `conversation.streamMessages()`.

A successfully received message (that makes it through the decoding and decryption without throwing) can be trusted to be authentic. Authentic means that it was sent by the owner of the `message.senderAddress` account and that it wasn't modified in transit. The `message.sent` timestamp can be trusted to have been set by the sender.
A successfully received message (that makes it through the decoding and decryption without throwing) can be trusted to be authentic. Authentic means that it was sent by the owner of the `message.senderInboxId` account and that it wasn't modified in transit. The `message.sent` timestamp can be trusted to have been set by the sender.

The flow returned by the `stream` methods is an asynchronous data stream that sequentially emits values and completes normally or with an exception.

```kotlin
conversation.streamMessages().collect {
if (it.senderAddress == client.address) {
if (it.senderInboxId == client.address) {
// This message was sent from me
}

print("New message from ${it.senderAddress}: ${it.body}")
print("New message from ${it.senderInboxId}: ${it.body}")
}
```

Expand Down
35 changes: 0 additions & 35 deletions dev/local/test/script.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ConversationViewHolder(
} else {
""
}
val isMe = item.mostRecentMessage?.senderAddress == ClientManager.client.address
val isMe = item.mostRecentMessage?.senderInboxId == ClientManager.client.address
if (messageBody.isNotBlank()) {
binding.messageBody.text = if (isMe) binding.root.resources.getString(
R.string.your_message_body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MessageViewHolder(
@SuppressLint("SetTextI18n")
fun bind(item: ConversationDetailViewModel.MessageListItem.Message) {
val isFromMe =
ClientManager.client.address.lowercase() == item.message.senderAddress.lowercase()
ClientManager.client.address.lowercase() == item.message.senderInboxId.lowercase()
val params = binding.messageContainer.layoutParams as ConstraintLayout.LayoutParams
if (isFromMe) {
params.rightToRight = PARENT_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,31 @@ class ClientTest {
val time3 = end3.time - start3.time
Log.d("PERF", "Built a client with inboxId in ${time3 / 1000.0}s")

val start4 = Date()
val buildClient3 = runBlocking {
Client().build(
fakeWallet.address,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.DEV, true),
appContext = context,
dbEncryptionKey = key
),
inboxId = client.inboxId,
apiClient = client.apiClient
)
}
val end4 = Date()
val time4 = end4.time - start4.time
Log.d("PERF", "Built a client with inboxId and apiClient in ${time4 / 1000.0}s")

assert(time2 < time1)
assert(time3 < time1)
assert(time3 < time2)
assert(time4 < time1)
assert(time4 < time2)
assert(time4 < time3)
assertEquals(client.inboxId, buildClient1.inboxId)
assertEquals(client.inboxId, buildClient2.inboxId)
assertEquals(client.inboxId, buildClient3.inboxId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ConversationsTest {
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
val dm = runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }

val sameDm = boClient.findConversationByTopic(dm.topic)
val sameGroup = boClient.findConversationByTopic(group.topic)
val sameDm = runBlocking { boClient.findConversationByTopic(dm.topic) }
val sameGroup = runBlocking { boClient.findConversationByTopic(group.topic) }
assertEquals(group.id, sameGroup?.id)
assertEquals(dm.id, sameDm?.id)
}
Expand Down Expand Up @@ -112,6 +112,28 @@ class ConversationsTest {
assertEquals(conversationsOrdered.map { it.id }, listOf(group2.id, dm.id, group1.id))
}

@Test
fun testsCanSyncAllConversationsFiltered() {
runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
val group =
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
assertEquals(runBlocking { boClient.conversations.syncAllConversations() }.toInt(), 2)
assertEquals(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt(),
2
)
runBlocking { group.updateConsentState(ConsentState.DENIED) }
assertEquals(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.ALLOWED) }.toInt(),
1
)
assertEquals(
runBlocking { boClient.conversations.syncAllConversations(consentState = ConsentState.DENIED) }.toInt(),
1
)
assertEquals(runBlocking { boClient.conversations.syncAllConversations() }.toInt(), 2)
}

@Test
fun testCanStreamAllMessages() {
val group =
Expand Down
43 changes: 29 additions & 14 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,19 @@ class DmTest {
runBlocking { dm.send("howdy") }
val messageId = runBlocking { dm.send("gm") }
runBlocking { dm.sync() }
assertEquals(dm.messages().first().body, "gm")
assertEquals(dm.messages().first().id, messageId)
assertEquals(dm.messages().first().deliveryStatus, MessageDeliveryStatus.PUBLISHED)
assertEquals(dm.messages().size, 2)
assertEquals(runBlocking { dm.messages() }.first().body, "gm")
assertEquals(runBlocking { dm.messages() }.first().id, messageId)
assertEquals(
runBlocking { dm.messages() }.first().deliveryStatus,
MessageDeliveryStatus.PUBLISHED
)
assertEquals(runBlocking { dm.messages() }.size, 2)

runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages().size, 2)
assertEquals(sameDm.messages().first().body, "gm")
assertEquals(runBlocking { sameDm.messages() }.size, 2)
assertEquals(runBlocking { sameDm.messages() }.first().body, "gm")
}

@Test
Expand All @@ -215,17 +218,29 @@ class DmTest {
dm.send("gm")
}

assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
assertEquals(runBlocking { dm.messages() }.size, 2)
assertEquals(
runBlocking { dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED) }.size,
2
)
runBlocking { dm.sync() }
assertEquals(dm.messages().size, 2)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 0)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
assertEquals(runBlocking { dm.messages() }.size, 2)
assertEquals(
runBlocking { dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED) }.size,
0
)
assertEquals(
runBlocking { dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED) }.size,
2
)

runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
assertEquals(
runBlocking { sameDm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED) }.size,
2
)
}

@Test
Expand All @@ -235,7 +250,7 @@ class DmTest {
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
runBlocking { dm.send("gm") }
runBlocking { dm.sync() }
val messageToReact = dm.messages()[0]
val messageToReact = runBlocking { dm.messages() }[0]

val reaction = Reaction(
reference = messageToReact.id,
Expand All @@ -252,7 +267,7 @@ class DmTest {
}
runBlocking { dm.sync() }

val messages = dm.messages()
val messages = runBlocking { dm.messages() }
assertEquals(messages.size, 2)
val content: Reaction? = messages.first().content()
assertEquals("U+1F603", content?.content)
Expand Down
Loading

0 comments on commit 8550d9c

Please sign in to comment.