Skip to content

Commit

Permalink
get all dm tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 16, 2024
1 parent 473e0fb commit 01c395b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
15 changes: 6 additions & 9 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,13 @@ class DmTest {
val boDm = runBlocking {
boClient.conversations.newConversation(alix.walletAddress)
}
runBlocking {
assertEquals("Starting Name", boDm.name)
assertEquals("startingurl.com", boDm.imageUrlSquare)
alixClient.conversations.syncGroups()
}
val alixDm = runBlocking { alixClient.conversations.listGroups().first() }

runBlocking { alixClient.conversations.syncConversations() }
val alixDm = runBlocking { alixClient.conversations.listDms().first() }
runBlocking {
alixDm.sync()
alixDm.updateGroupName("This Is A Great Group")
alixDm.updateGroupImageUrlSquare("thisisanewurl.com")
alixDm.updateName("This Is A Great Group")
alixDm.updateImageUrlSquare("thisisanewurl.com")
boDm.sync()
}
assertEquals("This Is A Great Group", boDm.name)
Expand Down Expand Up @@ -342,7 +339,7 @@ class DmTest {

val job = CoroutineScope(Dispatchers.IO).launch {
try {
alixClient.conversations.streamAllGroupDecryptedMessages().collect { message ->
alixClient.conversations.streamAllDmDecryptedMessages().collect { message ->
allMessages.add(message)
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,10 @@ class GroupTest {
val group2 =
caroClient.conversations.newGroup(listOf(bo.walletAddress))
assertEquals(group2.id, awaitItem().id)
//Does not stream DMs
val dm =
caroClient.conversations.findOrCreateDm(bo.walletAddress)
expectNoEvents()
cancelAndConsumeRemainingEvents()
}
}

Expand All @@ -769,7 +772,7 @@ class GroupTest {
alixClient.conversations.newConversation(bo.walletAddress)
Thread.sleep(2500)
caroClient.conversations.newGroup(listOf(alix.walletAddress))
//Does not stream DMs
caroClient.conversations.findOrCreateDm(alix.walletAddress)
}

Thread.sleep(2500)
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class Client() {

suspend fun findDm(address: String): Dm? {
val client = v3Client ?: throw XMTPException("Error no V3 client initialized")
val inboxId = inboxIdFromAddress(address) ?: throw XMTPException("No inboxId present")
val inboxId = inboxIdFromAddress(address.lowercase()) ?: throw XMTPException("No inboxId present")
try {
return Dm(this, client.dmConversation(inboxId))
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ data class Conversations(
}

suspend fun findOrCreateDm(peerAddress: String): Dm {
if (peerAddress.lowercase() == client.address.lowercase()) {
throw XMTPException("Recipient is sender")
}
val falseAddresses =
client.canMessageV3(listOf(peerAddress)).filter { !it.value }.map { it.key }
if (falseAddresses.isNotEmpty()) {
throw XMTPException("${falseAddresses.joinToString()} not on network")
}
var dm = client.findDm(peerAddress)
if (dm == null) {
val dmConversation = libXMTPConversations?.createDm(peerAddress)
val dmConversation = libXMTPConversations?.createDm(peerAddress.lowercase())
?: throw XMTPException("Client does not support V3 Dms")
dm = Dm(client, dmConversation)
client.contacts.allowGroups(groupIds = listOf(dm.id))
Expand Down

0 comments on commit 01c395b

Please sign in to comment.