Skip to content

Commit

Permalink
[V3] Consent follows ups (#309)
Browse files Browse the repository at this point in the history
* improvements from iOS work

* allow address

* rename all consent group to conversation

* return null if it errors

* small rename

* update library

* update bindings again

* update all the bindings

* update the consent filtering

* add a test for it

* update the tests

* add back the normal release flow

* update bindings

* bump the bindings as well

* add a way to just stream one or the other and order dms and groups

* get all the tests updated

* fix up lint
  • Loading branch information
nplasterer authored Nov 8, 2024
1 parent 9b9f628 commit 912714b
Show file tree
Hide file tree
Showing 15 changed files with 996 additions and 408 deletions.
28 changes: 12 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,33 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '17'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Run build with Gradle Wrapper
run: ./gradlew build

- name: Tag version 3.0.0
run: |
git tag 3.0.0
git push origin 3.0.0
- name: Create a GitHub release for version 3.0.0
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
release_branches: "release"
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: "3.0.0"
name: "Release 3.0.0"
body: "A XMTP MLS only SDK 3.0.0"

tag: ${{ steps.tag_version.outputs.new_version }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
- name: Gradle Publish
env:
RELEASE_VERSION: "3.0.0"
RELEASE_VERSION: ${{ steps.tag_version.outputs.new_version }}
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
SIGN_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
SIGN_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
MAVEN_PROFILE_ID: ${{ secrets.MAVEN_PROFILE_ID }}
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ClientTest {

runBlocking {
client.conversations.newGroup(listOf(client2.address))
client.conversations.syncConversations()
client.conversations.sync()
assertEquals(client.conversations.listGroups().size, 1)
}

Expand All @@ -116,7 +116,7 @@ class ClientTest {
)
}
runBlocking {
client.conversations.syncConversations()
client.conversations.sync()
assertEquals(client.conversations.listGroups().size, 0)
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ class ClientTest {

runBlocking {
boClient.conversations.newGroup(listOf(alixClient.address))
boClient.conversations.syncConversations()
boClient.conversations.sync()
}

runBlocking {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.xmtp.android.library

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -12,6 +13,7 @@ import org.junit.runner.RunWith
import org.xmtp.android.library.messages.PrivateKey
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
import java.security.SecureRandom

@RunWith(AndroidJUnit4::class)
class ConversationsTest {
Expand Down Expand Up @@ -61,7 +63,7 @@ class ConversationsTest {
assertEquals(runBlocking { boClient.conversations.listDms().size }, 1)
assertEquals(runBlocking { boClient.conversations.listGroups().size }, 1)

runBlocking { caroClient.conversations.syncConversations() }
runBlocking { caroClient.conversations.sync() }
assertEquals(
runBlocking { caroClient.conversations.list().size },
2
Expand Down Expand Up @@ -116,7 +118,7 @@ class ConversationsTest {
runBlocking { caroClient.conversations.newGroup(listOf(bo.walletAddress)) }
val conversation =
runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
runBlocking { boClient.conversations.syncConversations() }
runBlocking { boClient.conversations.sync() }

val allMessages = mutableListOf<DecodedMessage>()

Expand Down Expand Up @@ -164,4 +166,68 @@ class ConversationsTest {
assertEquals(2, allMessages.size)
job.cancel()
}

@Test
fun testSyncConsent() {
val key = SecureRandom().generateSeed(32)
val context = InstrumentationRegistry.getInstrumentation().targetContext
val alixWallet = PrivateKeyBuilder()

val alixClient = runBlocking {
Client().create(
account = alixWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
appContext = context,
dbEncryptionKey = key
)
)
}
val dm = runBlocking { alixClient.conversations.findOrCreateDm(bo.walletAddress) }
runBlocking {
dm.updateConsentState(ConsentState.DENIED)
assertEquals(dm.consentState(), ConsentState.DENIED)
boClient.conversations.sync()
}
val boDm = runBlocking { boClient.findConversation(dm.id) }
alixClient.dropLocalDatabaseConnection()
alixClient.deleteLocalDatabase()

val alixClient2 = runBlocking {
Client().create(
account = alixWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
appContext = context,
dbEncryptionKey = key
)
)
}

val state = runBlocking { alixClient2.inboxState(true) }
assertEquals(state.installations.size, 2)

runBlocking {
boClient.conversations.sync()
boDm?.sync()
alixClient2.conversations.sync()
val dm2 = alixClient2.findConversation(dm.id)!!
alixClient2.syncConsent()
assertEquals(dm2.consentState(), ConsentState.DENIED)
alixClient2.preferences.consentList.setConsentState(
listOf(
ConsentListEntry(
dm2.id,
EntryType.CONVERSATION_ID,
ConsentState.ALLOWED
)
)
)
assertEquals(
alixClient2.preferences.consentList.conversationState(dm2.id),
ConsentState.ALLOWED
)
assertEquals(dm2.consentState(), ConsentState.ALLOWED)
}
}
}
94 changes: 81 additions & 13 deletions library/src/androidTest/java/org/xmtp/android/library/DmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.Conversations.ConversationType
import org.xmtp.android.library.codecs.ContentTypeReaction
import org.xmtp.android.library.codecs.Reaction
import org.xmtp.android.library.codecs.ReactionAction
Expand Down Expand Up @@ -52,12 +54,24 @@ class DmTest {
fun testCanCreateADm() {
runBlocking {
val convo1 = boClient.conversations.findOrCreateDm(alix.walletAddress)
alixClient.conversations.syncConversations()
alixClient.conversations.sync()
val sameConvo1 = alixClient.conversations.findOrCreateDm(bo.walletAddress)
assertEquals(convo1.id, sameConvo1.id)
}
}

@Test
fun testsCanFindDmByAddress() {
runBlocking {
val dm = boClient.conversations.findOrCreateDm(caro.walletAddress)

val caroDm = boClient.findDm(caro.walletAddress)
val alixDm = boClient.findDm(alix.walletAddress)
assertNull(alixDm)
assertEquals(caroDm?.id, dm.id)
}
}

@Test
fun testCanListDmMembers() {
val dm = runBlocking {
Expand Down Expand Up @@ -114,11 +128,55 @@ class DmTest {
dm.send("howdy")
dm.send("gm")
dm.sync()
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.ALLOWED)
assertEquals(
boClient.preferences.consentList.conversationState(dm.id),
ConsentState.ALLOWED
)
assertEquals(dm.consentState(), ConsentState.ALLOWED)
}
}

@Test
fun testsCanListDmsFiltered() {
runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
2
)
runBlocking { dm.updateConsentState(ConsentState.DENIED) }
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.ALLOWED).size },
1
)
assertEquals(
runBlocking { boClient.conversations.listDms(consentState = ConsentState.DENIED).size },
1
)
assertEquals(runBlocking { boClient.conversations.listDms().size }, 2)
}

@Test
fun testCanListDmsOrder() {
val dm1 = runBlocking { boClient.conversations.findOrCreateDm(caro.walletAddress) }
val dm2 =
runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
val group =
runBlocking { boClient.conversations.newGroup(listOf(caro.walletAddress)) }
runBlocking { dm2.send("Howdy") }
runBlocking { group.send("Howdy") }
runBlocking { boClient.conversations.syncAllConversations() }
val conversations = runBlocking { boClient.conversations.listDms() }
val conversationsOrdered =
runBlocking { boClient.conversations.listDms(order = Conversations.ConversationOrder.LAST_MESSAGE) }
assertEquals(conversations.size, 2)
assertEquals(conversationsOrdered.size, 2)
assertEquals(conversations.map { it.id }, listOf(dm1.id, dm2.id))
assertEquals(conversationsOrdered.map { it.id }, listOf(dm2.id, dm1.id))
}

@Test
fun testCanSendMessageToDm() {
val dm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
Expand All @@ -130,7 +188,7 @@ class DmTest {
assertEquals(dm.messages().first().deliveryStatus, MessageDeliveryStatus.PUBLISHED)
assertEquals(dm.messages().size, 3)

runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages().size, 2)
Expand All @@ -152,7 +210,7 @@ class DmTest {
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.UNPUBLISHED).size, 0)
assertEquals(dm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 3)

runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }
val sameDm = runBlocking { alixClient.conversations.listDms().last() }
runBlocking { sameDm.sync() }
assertEquals(sameDm.messages(deliveryStatus = MessageDeliveryStatus.PUBLISHED).size, 2)
Expand Down Expand Up @@ -194,7 +252,7 @@ class DmTest {
@Test
fun testCanStreamDmMessages() = kotlinx.coroutines.test.runTest {
val group = boClient.conversations.findOrCreateDm(alix.walletAddress.lowercase())
alixClient.conversations.syncConversations()
alixClient.conversations.sync()
val alixDm = alixClient.findDm(bo.walletAddress)
group.streamMessages().test {
alixDm?.send("hi")
Expand All @@ -207,15 +265,16 @@ class DmTest {
@Test
fun testCanStreamAllMessages() {
val boDm = runBlocking { boClient.conversations.findOrCreateDm(alix.walletAddress) }
runBlocking { alixClient.conversations.syncConversations() }
runBlocking { alixClient.conversations.sync() }

val allMessages = mutableListOf<DecodedMessage>()

val job = CoroutineScope(Dispatchers.IO).launch {
try {
alixClient.conversations.streamAllMessages().collect { message ->
allMessages.add(message)
}
alixClient.conversations.streamAllMessages(type = ConversationType.DMS)
.collect { message ->
allMessages.add(message)
}
} catch (e: Exception) {
}
}
Expand Down Expand Up @@ -243,7 +302,7 @@ class DmTest {

@Test
fun testCanStreamConversations() = kotlinx.coroutines.test.runTest {
boClient.conversations.stream().test {
boClient.conversations.stream(type = ConversationType.DMS).test {
val dm =
alixClient.conversations.findOrCreateDm(bo.walletAddress)
assertEquals(dm.id, awaitItem().id)
Expand All @@ -258,7 +317,10 @@ class DmTest {
runBlocking {
val dm =
boClient.conversations.findOrCreateDm(alix.walletAddress)
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.ALLOWED)
assertEquals(
boClient.preferences.consentList.conversationState(dm.id),
ConsentState.ALLOWED
)

assertEquals(dm.consentState(), ConsentState.ALLOWED)

Expand All @@ -271,7 +333,10 @@ class DmTest {
)
)
)
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.DENIED)
assertEquals(
boClient.preferences.consentList.conversationState(dm.id),
ConsentState.DENIED
)
assertEquals(dm.consentState(), ConsentState.DENIED)

boClient.preferences.consentList.setConsentState(
Expand All @@ -283,7 +348,10 @@ class DmTest {
)
)
)
assertEquals(boClient.preferences.consentList.conversationState(dm.id), ConsentState.ALLOWED)
assertEquals(
boClient.preferences.consentList.conversationState(dm.id),
ConsentState.ALLOWED
)
assertEquals(dm.consentState(), ConsentState.ALLOWED)
}
}
Expand Down
Loading

0 comments on commit 912714b

Please sign in to comment.