Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update consent syncing and removes group update message from dms #536

Merged
merged 7 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:3.0.4"
implementation "org.xmtp:android:3.0.5"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class XMTPModule : Module() {
val historySyncUrl = authOptions.historySyncUrl
?: when (authOptions.environment) {
"production" -> "https://message-history.production.ephemera.network/"
"local" -> "http://0.0.0.0:5558"
"local" -> "http://10.0.2.2:5558"
else -> "https://message-history.dev.ephemera.network/"
}
return ClientOptions(
Expand Down Expand Up @@ -438,41 +438,43 @@ class XMTPModule : Module() {
).toJson()
}

AsyncFunction("listGroups") Coroutine { inboxId: String, groupParams: String?, sortOrder: String?, limit: Int? ->
AsyncFunction("listGroups") Coroutine { inboxId: String, groupParams: String?, sortOrder: String?, limit: Int?, consentState: String? ->
withContext(Dispatchers.IO) {
logV("listGroups")
val client = clients[inboxId] ?: throw XMTPException("No client")
val params = ConversationParamsWrapper.conversationParamsFromJson(groupParams ?: "")
val order = getConversationSortOrder(sortOrder ?: "")
val groups = client.conversations.listGroups(order = order, limit = limit)
val consent = consentState?.let { getConsentState(it) }
val groups = client.conversations.listGroups(order = order, limit = limit, consentState = consent)
groups.map { group ->
GroupWrapper.encode(client, group, params)
}
}
}

AsyncFunction("listDms") Coroutine { inboxId: String, groupParams: String?, sortOrder: String?, limit: Int? ->
AsyncFunction("listDms") Coroutine { inboxId: String, groupParams: String?, sortOrder: String?, limit: Int?, consentState: String? ->
withContext(Dispatchers.IO) {
logV("listDms")
val client = clients[inboxId] ?: throw XMTPException("No client")
val params = ConversationParamsWrapper.conversationParamsFromJson(groupParams ?: "")
val order = getConversationSortOrder(sortOrder ?: "")
val dms = client.conversations.listDms(order = order, limit = limit)
val consent = consentState?.let { getConsentState(it) }
val dms = client.conversations.listDms(order = order, limit = limit, consentState = consent)
dms.map { dm ->
DmWrapper.encode(client, dm, params)
}
}
}

AsyncFunction("listConversations") Coroutine { inboxId: String, conversationParams: String?, sortOrder: String?, limit: Int? ->
AsyncFunction("listConversations") Coroutine { inboxId: String, conversationParams: String?, sortOrder: String?, limit: Int?, consentState: String? ->
withContext(Dispatchers.IO) {
logV("listConversations")
val client = clients[inboxId] ?: throw XMTPException("No client")
val params =
ConversationParamsWrapper.conversationParamsFromJson(conversationParams ?: "")
val order = getConversationSortOrder(sortOrder ?: "")
val conversations =
client.conversations.list(order = order, limit = limit)
val consent = consentState?.let { getConsentState(it) }
val conversations = client.conversations.list(order = order, limit = limit, consentState = consent)
conversations.map { conversation ->
ConversationWrapper.encode(client, conversation, params)
}
Expand Down Expand Up @@ -1060,6 +1062,13 @@ class XMTPModule : Module() {
}
}

AsyncFunction("syncConsent") Coroutine { inboxId: String ->
withContext(Dispatchers.IO) {
val client = clients[inboxId] ?: throw XMTPException("No client")
client.syncConsent()
}
}

AsyncFunction("setConsentState") Coroutine { inboxId: String, value: String, entryType: String, consentType: String ->
withContext(Dispatchers.IO) {
val client = clients[inboxId] ?: throw XMTPException("No client")
Expand Down
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (3.0.0)
- LibXMTP (3.0.1)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (2.0.0):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (3.0.4):
- XMTP (3.0.5):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 3.0.0)
- LibXMTP (= 3.0.1)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 3.0.4)
- XMTP (= 3.0.5)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: 4ef99026c3b353bd27195b48580e1bd34d083c3a
LibXMTP: b23a18d05d458fee72f0a96a114b1eb1e6d77d3b
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: f7d1d5945c8765f97f39c3d121f353d46735d801
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: dba23b4f3bcee464ca2f7569e1dc05fd9f4c0148
XMTPReactNative: 117d8a00b063044029c11f50320a6b9c8abcdea7
XMTP: 7b9105a3549427a294fb991c5892ebec73d2388d
XMTPReactNative: 0862a746eaddb7d643ad4cbdc2727d02863d9a18
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
Expand Down
81 changes: 76 additions & 5 deletions example/src/tests/conversationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,63 @@ test('can find a dm by address', async () => {
return true
})

test('can filter conversations by consent', async () => {
const [alixClient, boClient, caroClient] = await createClients(3)

const boGroup1 = await boClient.conversations.newGroup([alixClient.address])
const otherGroup = await alixClient.conversations.newGroup([boClient.address])
const boDm1 = await boClient.conversations.findOrCreateDm(alixClient.address)
await caroClient.conversations.findOrCreateDm(boClient.address)
await boClient.conversations.sync()
const boDm2 = await boClient.conversations.findDmByInboxId(caroClient.inboxId)
const boGroup2 = await boClient.conversations.findGroup(otherGroup.id)

const boConvos = await boClient.conversations.list()
const boConvosFilteredAllowed = await boClient.conversations.list(
{},
undefined,
undefined,
'allowed'
)
const boConvosFilteredUnknown = await boClient.conversations.list(
{},
undefined,
undefined,
'unknown'
)

assert(
boConvos.length === 4,
`Conversation length should be 4 but was ${boConvos.length}`
)

assert(
boConvosFilteredAllowed
.map((conversation: any) => conversation.id)
.toString() === [boGroup1.id, boDm1.id].toString(),
`Conversation allowed should be ${[
boGroup1.id,
boDm1.id,
].toString()} but was ${boConvosFilteredAllowed
.map((convo: any) => convo.id)
.toString()}`
)

assert(
boConvosFilteredUnknown
.map((conversation: any) => conversation.id)
.toString() === [boGroup2?.id, boDm2?.id].toString(),
`Conversation unknown filter should be ${[
boGroup2?.id,
boDm2?.id,
].toString()} but was ${boConvosFilteredUnknown
.map((convo: any) => convo.id)
.toString()}`
)

return true
})

test('can list conversations with params', async () => {
const [alixClient, boClient, caroClient] = await createClients(3)

Expand Down Expand Up @@ -124,13 +181,27 @@ test('can list conversations with params', async () => {
assert(
boConvosOrderCreated.map((group: any) => group.id).toString() ===
[boGroup1.id, boGroup2.id, boDm1.id, boDm2.id].toString(),
`Conversation created at order should be ${[boGroup1.id, boGroup2.id, boDm1.id, boDm2.id].toString()} but was ${boConvosOrderCreated.map((group: any) => group.id).toString()}`
`Conversation created at order should be ${[
boGroup1.id,
boGroup2.id,
boDm1.id,
boDm2.id,
].toString()} but was ${boConvosOrderCreated
.map((group: any) => group.id)
.toString()}`
)

assert(
boConvosOrderLastMessage.map((group: any) => group.id).toString() ===
[boDm1.id, boGroup2.id, boDm2.id, boGroup1.id].toString(),
`Conversation last message order should be ${[boDm1.id, boGroup2.id, boDm2.id, boGroup1.id].toString()} but was ${boConvosOrderLastMessage.map((group: any) => group.id).toString()}`
`Conversation last message order should be ${[
boDm1.id,
boGroup2.id,
boDm2.id,
boGroup1.id,
].toString()} but was ${boConvosOrderLastMessage
.map((group: any) => group.id)
.toString()}`
)

const messages = await boConvosOrderLastMessage[0].messages()
Expand Down Expand Up @@ -213,12 +284,12 @@ test('can list conversation messages', async () => {

assert(
boGroupMessages?.length === 3,
`bo conversation lengths should be 4 but was ${boGroupMessages?.length}`
`bo conversation lengths should be 3 but was ${boGroupMessages?.length}`
)

assert(
boDmMessages?.length === 3,
`alix conversation lengths should be 3 but was ${boDmMessages?.length}`
boDmMessages?.length === 2,
`alix conversation lengths should be 2 but was ${boDmMessages?.length}`
)

return true
Expand Down
69 changes: 67 additions & 2 deletions example/src/tests/dmTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,61 @@ function test(name: string, perform: () => Promise<boolean>) {
})
}

test('can filter dms by consent', async () => {
const [alixClient, boClient, caroClient] = await createClients(3)

await boClient.conversations.newGroup([alixClient.address])
const otherGroup = await alixClient.conversations.newGroup([boClient.address])
const boDm1 = await boClient.conversations.findOrCreateDm(alixClient.address)
await caroClient.conversations.findOrCreateDm(boClient.address)
await boClient.conversations.sync()
const boDm2 = await boClient.conversations.findDmByInboxId(caroClient.inboxId)
await boClient.conversations.findGroup(otherGroup.id)

const boConvos = await boClient.conversations.listDms()
const boConvosFilteredAllowed = await boClient.conversations.listDms(
{},
undefined,
undefined,
'allowed'
)
const boConvosFilteredUnknown = await boClient.conversations.listDms(
{},
undefined,
undefined,
'unknown'
)

assert(
boConvos.length === 2,
`Conversation length should be 2 but was ${boConvos.length}`
)

assert(
boConvosFilteredAllowed
.map((conversation: any) => conversation.id)
.toString() === [boDm1.id].toString(),
`Conversation allowed should be ${[
boDm1.id,
].toString()} but was ${boConvosFilteredAllowed
.map((convo: any) => convo.id)
.toString()}`
)

assert(
boConvosFilteredUnknown
.map((conversation: any) => conversation.id)
.toString() === [boDm2?.id].toString(),
`Conversation unknown filter should be ${[
boDm2?.id,
].toString()} but was ${boConvosFilteredUnknown
.map((convo: any) => convo.id)
.toString()}`
)

return true
})

test('can list dms with params', async () => {
const [alixClient, boClient, caroClient] = await createClients(3)

Expand Down Expand Up @@ -37,14 +92,24 @@ test('can list dms with params', async () => {
boConvosOrderCreated
.map((conversation: any) => conversation.id)
.toString() === [boDm1.id, boDm2.id].toString(),
`Conversation created at order should be ${[boDm1.id, boDm2.id].toString()} but was ${boConvosOrderCreated.map((convo: any) => convo.id).toString()}`
`Conversation created at order should be ${[
boDm1.id,
boDm2.id,
].toString()} but was ${boConvosOrderCreated
.map((convo: any) => convo.id)
.toString()}`
)

assert(
boConvosOrderLastMessage
.map((conversation: any) => conversation.id)
.toString() === [boDm1.id, boDm2.id].toString(),
`Conversation last message order should be ${[boDm1.id, boDm2.id].toString()} but was ${boConvosOrderLastMessage.map((convo: any) => convo.id).toString()}`
`Conversation last message order should be ${[
boDm1.id,
boDm2.id,
].toString()} but was ${boConvosOrderLastMessage
.map((convo: any) => convo.id)
.toString()}`
)

const messages = await boConvosOrderLastMessage[0].messages()
Expand Down
Loading
Loading