Skip to content

Commit

Permalink
remove client from serializable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jan 14, 2025
1 parent 6d6441a commit 8a124d0
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 251 deletions.
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.20"
implementation "org.xmtp:android:3.0.21"
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 @@ -450,7 +450,16 @@ class XMTPModule : Module() {
logV("staticCanMessage")
Client.canMessage(
peerAddresses,
context,
apiEnvironments(environment, null),
)
}
}

AsyncFunction("staticInboxStatesForInboxIds") Coroutine { environment: String, inboxIds: List<String> ->
withContext(Dispatchers.IO) {
logV("staticInboxStatesForInboxIds")
Client.inboxStatesForInboxIds(
inboxIds,
apiEnvironments(environment, null),
)
}
Expand Down
3 changes: 2 additions & 1 deletion example/src/ConversationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
StaticAttachmentContent,
ReplyContent,
useClient,
Client,
} from 'xmtp-react-native-sdk'
import { ConversationSendPayload } from 'xmtp-react-native-sdk/lib/types'

Expand Down Expand Up @@ -1111,7 +1112,7 @@ function MessageContents({
if (contentTypeId === 'xmtp.org/reply:1.0') {
const replyContent: ReplyContent = content
const replyContentType = replyContent.contentType
const codec = client?.codecRegistry[replyContentType]
const codec = Client.codecRegistry[replyContentType]
const actualReplyContent = codec?.decode(replyContent.content)

return (
Expand Down
4 changes: 2 additions & 2 deletions example/src/GroupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
ReplyContent,
useClient,
GroupUpdatedContent,
Client,
} from 'xmtp-react-native-sdk'
import { ConversationSendPayload } from 'xmtp-react-native-sdk/lib/types'

Expand Down Expand Up @@ -1155,8 +1156,7 @@ function MessageContents({

if (contentTypeId === 'xmtp.org/reply:1.0') {
const replyContent: ReplyContent = content
const replyContentType = replyContent.contentType
const codec = client?.codecRegistry[replyContentType]
const codec = Client.codecRegistry[contentTypeId]
const actualReplyContent = codec?.decode(replyContent.content)

return (
Expand Down
40 changes: 19 additions & 21 deletions example/src/tests/conversationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,32 @@ test('register and use custom content types', async () => {
233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64,
166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145,
])
const bob = await Client.createRandom({
const bo = await Client.createRandom({
env: 'local',
codecs: [new NumberCodec()],
dbEncryptionKey: keyBytes,
})
const alice = await Client.createRandom({
const alix = await Client.createRandom({
env: 'local',
codecs: [new NumberCodec()],
dbEncryptionKey: keyBytes,
})

bob.register(new NumberCodec())
alice.register(new NumberCodec())
Client.register(new NumberCodec())

await delayToPropogate()

const bobConvo = await bob.conversations.newConversation(alice.address)
const boConvo = await bo.conversations.newConversation(alix.address)
await delayToPropogate()
await bobConvo.send(
await boConvo.send(
{ topNumber: { bottomNumber: 12 } },
{ contentType: ContentTypeNumber }
)

await alice.conversations.syncAllConversations()
const aliceConvo = await alice.conversations.findConversation(bobConvo.id)
await alix.conversations.syncAllConversations()
const alixConvo = await alix.conversations.findConversation(boConvo.id)

const messages = await aliceConvo!.messages()
const messages = await alixConvo!.messages()
assert(messages.length === 1, 'did not get messages')

const message = messages[0]
Expand All @@ -150,34 +149,33 @@ test('register and use custom content types with prepare', async () => {
233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64,
166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145,
])
const bob = await Client.createRandom({
const bo = await Client.createRandom({
env: 'local',
codecs: [new NumberCodec()],
dbEncryptionKey: keyBytes,
})
const alice = await Client.createRandom({
const alix = await Client.createRandom({
env: 'local',
codecs: [new NumberCodec()],
dbEncryptionKey: keyBytes,
})

bob.register(new NumberCodec())
alice.register(new NumberCodec())
Client.register(new NumberCodec())

await delayToPropogate()

const bobConvo = await bob.conversations.newConversation(alice.address)
const boConvo = await bo.conversations.newConversation(alix.address)
await delayToPropogate()
await bobConvo.prepareMessage(
await boConvo.prepareMessage(
{ topNumber: { bottomNumber: 12 } },
{ contentType: ContentTypeNumber }
)
await bobConvo.publishPreparedMessages()
await boConvo.publishPreparedMessages()

await alice.conversations.syncAllConversations()
const aliceConvo = await alice.conversations.findConversation(bobConvo.id)
await alix.conversations.syncAllConversations()
const alixConvo = await alix.conversations.findConversation(boConvo.id)

const messages = await aliceConvo!.messages()
const messages = await alixConvo!.messages()
assert(messages.length === 1, 'did not get messages')

const message = messages[0]
Expand Down Expand Up @@ -210,8 +208,8 @@ test('handle fallback types appropriately', async () => {
env: 'local',
dbEncryptionKey: keyBytes,
})
bob.register(new NumberCodecEmptyFallback())
bob.register(new NumberCodecUndefinedFallback())
Client.register(new NumberCodecEmptyFallback())
Client.register(new NumberCodecUndefinedFallback())
const bobConvo = await bob.conversations.newConversation(alice.address)

// @ts-ignore
Expand Down
16 changes: 8 additions & 8 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Wallet } from 'ethers'
import { DefaultContentTypes } from 'xmtp-react-native-sdk/lib/types/DefaultContentType'

import {
Test,
Expand All @@ -16,7 +17,6 @@ import {
DecodedMessage,
ConsentRecord,
} from '../../../src/index'
import { DefaultContentTypes } from 'xmtp-react-native-sdk/lib/types/DefaultContentType'

export const groupTests: Test[] = []
let counter = 1
Expand Down Expand Up @@ -84,12 +84,12 @@ test('groups cannot fork', async () => {
const lastMessage = messages[0]
// console.log(lastMessage);
console.log(
`${receiverGroupToCheck.client.address} sees ${messages.length} messages in group`
`${receiverGroupToCheck.clientInstallationId} sees ${messages.length} messages in group`
)
assert(
lastMessage !== undefined &&
lastMessage.nativeContent.text === messageContent,
`${receiverGroupToCheck.client.address} should have received the message, FORK? ${lastMessage?.nativeContent.text} !== ${messageContent}`
`${receiverGroupToCheck.clientInstallationId} should have received the message, FORK? ${lastMessage?.nativeContent.text} !== ${messageContent}`
)
// }
}
Expand Down Expand Up @@ -203,12 +203,12 @@ test('groups cannot fork short version', async () => {
})
const lastMessage = messages[0]
console.log(
`${receiverGroup.client.address} sees ${messages.length} messages in group`
`${receiverGroup.clientInstallationId} sees ${messages.length} messages in group`
)
assert(
lastMessage !== undefined &&
lastMessage.nativeContent.text === messageContent,
`${receiverGroup.client.address} should have received the message, FORK? ${lastMessage?.nativeContent.text} !== ${messageContent}`
`${receiverGroup.clientInstallationId} should have received the message, FORK? ${lastMessage?.nativeContent.text} !== ${messageContent}`
)
}
// When forked, it stays forked even if we try 5 times
Expand Down Expand Up @@ -279,12 +279,12 @@ test('groups cannot fork short version - update metadata', async () => {
})
const lastMessage = messages[0]
console.log(
`${receiverGroup.client.address} sees ${messages.length} messages in group`
`${receiverGroup.clientInstallationId} sees ${messages.length} messages in group`
)
assert(
lastMessage !== undefined &&
lastMessage.nativeContent.text === messageContent,
`${receiverGroup.client.address} should have received the message, FORK? ${lastMessage?.nativeContent.text} !== ${messageContent}`
`${receiverGroup.clientInstallationId} should have received the message, FORK? ${lastMessage?.nativeContent.text} !== ${messageContent}`
)
}
// When forked, it stays forked even if we try 5 times
Expand Down Expand Up @@ -1211,7 +1211,7 @@ test('can stream group messages', async () => {

test('can make a group with metadata', async () => {
const [alix, bo] = await createClients(2)
bo.register(new GroupUpdatedCodec())
Client.register(new GroupUpdatedCodec())

const alixGroup = await alix.conversations.newGroup([bo.address], {
name: 'Start Name',
Expand Down
4 changes: 2 additions & 2 deletions example/src/tests/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export async function createClients(
env: env ?? 'local',
dbEncryptionKey: keyBytes,
})
client.register(new GroupUpdatedCodec())
client.register(new RemoteAttachmentCodec())
Client.register(new GroupUpdatedCodec())
Client.register(new RemoteAttachmentCodec())
clients.push(client)
}
return clients
Expand Down
Loading

0 comments on commit 8a124d0

Please sign in to comment.