Skip to content

Commit

Permalink
Merge branch 'noe/fork-reproduction-test' into cv/adjustments/noe/for…
Browse files Browse the repository at this point in the history
…k-reproduction-test
  • Loading branch information
cameronvoell committed Nov 18, 2024
2 parents 8a1c488 + 7debadf commit d43aabc
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 529 deletions.
389 changes: 33 additions & 356 deletions README.md

Large diffs are not rendered by default.

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.3"
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 @@ -274,6 +274,14 @@ class XMTPModule : Module() {
}
}

AsyncFunction("getInboxStates") Coroutine { inboxId: String, refreshFromNetwork: Boolean, inboxIds: List<String> ->
withContext(Dispatchers.IO) {
val client = clients[inboxId] ?: throw XMTPException("No client")
val inboxStates = client.inboxStatesForInboxIds(refreshFromNetwork, inboxIds)
inboxStates.map { InboxStateWrapper.encode(it) }
}
}

Function("preAuthenticateToInboxCallbackCompleted") {
logV("preAuthenticateToInboxCallbackCompleted")
preAuthenticateToInboxCallbackDeferred?.complete(Unit)
Expand Down Expand Up @@ -430,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 @@ -531,11 +541,22 @@ class XMTPModule : Module() {
}
}

AsyncFunction("findDmByInboxId") Coroutine { inboxId: String, peerInboxId: String ->
withContext(Dispatchers.IO) {
logV("findDmByInboxId")
val client = clients[inboxId] ?: throw XMTPException("No client")
val dm = client.findDmByInboxId(peerInboxId)
dm?.let {
DmWrapper.encode(client, dm)
}
}
}

AsyncFunction("findDmByAddress") Coroutine { inboxId: String, peerAddress: String ->
withContext(Dispatchers.IO) {
logV("findDmByAddress")
val client = clients[inboxId] ?: throw XMTPException("No client")
val dm = client.findDm(peerAddress)
val dm = client.findDmByAddress(peerAddress)
dm?.let {
DmWrapper.encode(client, dm)
}
Expand Down Expand Up @@ -1041,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.3):
- 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.3)
- 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: ab14d9456330823f1c52b08ce5281d1e20c03f7f
XMTPReactNative: f7c9dc2eadef5c7d9590d2b7764ab805d16c7a5e
XMTP: 7b9105a3549427a294fb991c5892ebec73d2388d
XMTPReactNative: 0862a746eaddb7d643ad4cbdc2727d02863d9a18
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
Expand Down
16 changes: 16 additions & 0 deletions example/src/tests/clientTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,19 @@ test('production client creation does not error', async () => {
}
return true
})

test('can find others inbox states', async () => {
const [alix, bo, caro] = await createClients(3)

const states = await alix.inboxStates(true, [bo.inboxId, caro.inboxId])
assert(
states[0].recoveryAddress.toLowerCase === bo.address.toLowerCase,
`addresses dont match ${states[0].recoveryAddress} and ${bo.address}`
)
assert(
states[1].addresses[0].toLowerCase === caro.address.toLowerCase,
`clients dont match ${states[1].addresses[0]} and ${caro.address}`
)

return true
})
96 changes: 91 additions & 5 deletions example/src/tests/conversationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ test('can find a conversation by topic', async () => {
return true
})

test('can find a dm by inbox id', async () => {
const [alixClient, boClient] = await createClients(2)
const alixDm = await alixClient.conversations.findOrCreateDm(boClient.address)

await boClient.conversations.sync()
const boDm = await boClient.conversations.findDmByInboxId(alixClient.inboxId)

assert(
boDm?.id === alixDm.id,
`bo dm id ${boDm?.id} does not match alix dm id ${alixDm.id}`
)

return true
})

test('can find a dm by address', async () => {
const [alixClient, boClient] = await createClients(2)
const alixDm = await alixClient.conversations.findOrCreateDm(boClient.address)
Expand All @@ -82,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 @@ -109,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 @@ -198,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
Loading

0 comments on commit d43aabc

Please sign in to comment.