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

Fix timeout errors and add more fields to GroupWrapper #470

Merged
merged 9 commits into from
Aug 19, 2024
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:0.15.2"
implementation "org.xmtp:android:0.15.3"
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 @@ -13,11 +13,12 @@ class GroupWrapper {
"clientAddress" to client.address,
"id" to group.id,
"createdAt" to group.createdAt.time,
"peerInboxIds" to group.peerInboxIds(),
"members" to group.members().map { MemberWrapper.encode(it) },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to duplicate the DB call to members so this is a breaking change for anyone who is using peerInboxIds directly but is easily mitigated by mapping on inboxID if desired.

"version" to "GROUP",
"topic" to group.topic,
"creatorInboxId" to group.creatorInboxId(),
"isActive" to group.isActive(),
"addedByInboxId" to group.addedByInboxId(),
"name" to group.name,
"imageUrlSquare" to group.imageUrlSquare,
"description" to group.description
Expand Down
16 changes: 8 additions & 8 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 (0.5.7-beta0)
- LibXMTP (0.5.7-beta3)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.9):
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.14.1):
- XMTP (0.14.6):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.7-beta0)
- LibXMTP (= 0.5.7-beta3)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.14.1)
- XMTP (= 0.14.6)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,7 +711,7 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: d80a1a7c9c748fba81d80b95c62fd075a89224a2
LibXMTP: b6b930f9d2394a560d7f83b02be6ccd789472422
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 817ba1eea17421547e01e087285606eb270a8dcb
Expand Down Expand Up @@ -763,10 +763,10 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 593cf8bf4e9dc0737a6efc90a0e51fe7602101fd
XMTPReactNative: 1ca02155e4583791c8c99a244206ecf8e057abd2
XMTP: 0f36b44b3922a5933e3487bf09671655e05dcb8d
XMTPReactNative: 71910c6588e526d85583c1f7aeb6c83816747aea
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd
PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.15.2
57 changes: 30 additions & 27 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@

await boClient.conversations.syncGroups()
const boGroup = (await boClient.conversations.listGroups())[0]
const addedByInboxId = await boGroup.addedByInboxId()
const addedByInboxId = await boGroup.addedByInboxId

assert(
addedByInboxId === alixClient.inboxId,
Expand All @@ -452,7 +452,7 @@
const [alixClient, boClient] = await createClients(2)
const group = await alixClient.conversations.newGroup([boClient.address])

const members = await group.members()
const members = group.members

assert(members.length === 2, `Should be 2 members but was ${members.length}`)

Expand Down Expand Up @@ -514,10 +514,7 @@
if (memberInboxIds.length !== 3) {
throw new Error('num group members should be 3')
}
const peerInboxIds = await alixGroup.peerInboxIds
if (peerInboxIds.length !== 2) {
throw new Error('num peer group members should be 2')
}

if (
!(
memberInboxIds.includes(alixClient.inboxId) &&
Expand All @@ -528,15 +525,6 @@
throw new Error('missing address')
}

if (
!(
peerInboxIds.includes(boClient.inboxId) &&
peerInboxIds.includes(caroClient.inboxId)
)
) {
throw new Error('should include self')
}

// alix can send messages
await alixGroup.send('hello, world')
await alixGroup.send('gm')
Expand Down Expand Up @@ -962,6 +950,8 @@
throw Error('Unexpected num groups (should be 1): ' + groups.length)
}

assert(groups[0].members.length == 2, "should be 2")

Check warning on line 953 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '===' and instead saw '=='

Check warning on line 953 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"should·be·2"` with `'should·be·2'`

// bo creates a group with alix so a stream callback is fired
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const boGroup = await boClient.conversations.newGroup([alixClient.address])
Expand Down Expand Up @@ -2047,12 +2037,9 @@
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 wallet1 = new Wallet(
'0xc54c62dd3ad018ef94f20f0722cae33919e65270ad74f2d1794291088800f788'
)
const wallet2 = new Wallet(
'0x8d40c1c40473975cc6bbdc0465e70cc2e98f45f3c3474ca9b809caa9c4f53c0b'
)
const wallet1 = Wallet.createRandom()
const wallet2 = Wallet.createRandom()
Comment on lines +2040 to +2041
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These wallets are in the bad key package state so had to use random ones. I think this is better anyways. But good to know for future testing when we have a fix.


const client1 = await Client.create(wallet1, {
env: 'local',
appVersion: 'Testing/0.0.0',
Expand All @@ -2077,13 +2064,10 @@
await client1Group?.sync()
await client2Group?.sync()

assert(
(await client1Group?.members())?.length === 2,
`client 1 should see 2 members`
)
assert(client1Group?.members?.length === 2, `client 1 should see 2 members`)

assert(
(await client2Group?.members())?.length === 2,
(await client2Group?.membersList())?.length === 2,
`client 2 should see 2 members`
)

Expand All @@ -2100,13 +2084,32 @@

await client1Group?.send('This message will break the group')
assert(
(await client1Group?.members())?.length === 2,
client1Group?.members?.length === 2,
`client 1 should still see the 2 members`
)

return true
})

test('can list many groups members in parallel', async () => {
const [alix, bo] = await createClients(2)
const groups: Group[] = await createGroups(alix, [bo], 20, 0)

try {
await Promise.all(groups.slice(0, 10).map((g) => g.membersList()))
} catch (e) {
throw new Error(`Failed listing 10 groups members with ${e}`)
}

try {
await Promise.all(groups.slice(0, 20).map((g) => g.membersList()))
} catch (e) {
throw new Error(`Failed listing 20 groups members with ${e}`)
}

return true
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only left this one test that was previously failing for me and passing now.


// Commenting this out so it doesn't block people, but nice to have?
// test('can stream messages for a long time', async () => {
// const bo = await Client.createRandom({ env: 'local', enableV3: true })
Expand Down
3 changes: 2 additions & 1 deletion ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ struct GroupWrapper {
"clientAddress": client.address,
"id": group.id,
"createdAt": UInt64(group.createdAt.timeIntervalSince1970 * 1000),
"peerInboxIds": try group.peerInboxIds,
"members": try group.members.compactMap { member in return try MemberWrapper.encode(member) },
"version": "GROUP",
"topic": group.topic,
"creatorInboxId": try group.creatorInboxId(),
"isActive": try group.isActive(),
"addedByInboxId": try group.addedByInboxId(),
"name": try group.groupName(),
"imageUrlSquare": try group.groupImageUrlSquare(),
"description": try group.groupDescription()
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.14.5"
s.dependency "XMTP", "= 0.14.6"
end
64 changes: 41 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,19 @@ export async function createGroup<
description,
pinnedFrameUrl,
}
return new Group(
client,
JSON.parse(
await XMTPModule.createGroup(
client.inboxId,
peerAddresses,
permissionLevel,
JSON.stringify(options)
)
const group = JSON.parse(
await XMTPModule.createGroup(
client.inboxId,
peerAddresses,
permissionLevel,
JSON.stringify(options)
)
)

const members = group['members'].map((mem: string) => {
return Member.from(mem)
})
return new Group(client, group, members)
}

export async function createGroupCustomPermissions<
Expand All @@ -212,24 +214,29 @@ export async function createGroupCustomPermissions<
description,
pinnedFrameUrl,
}
return new Group(
client,
JSON.parse(
await XMTPModule.createGroupCustomPermissions(
client.inboxId,
peerAddresses,
JSON.stringify(permissionPolicySet),
JSON.stringify(options)
)
const group = JSON.parse(
await XMTPModule.createGroupCustomPermissions(
client.inboxId,
peerAddresses,
JSON.stringify(permissionPolicySet),
JSON.stringify(options)
)
)
const members = group['members'].map((mem: string) => {
return Member.from(mem)
})
return new Group(client, group, members)
}

export async function listGroups<
ContentTypes extends DefaultContentTypes = DefaultContentTypes,
>(client: Client<ContentTypes>): Promise<Group<ContentTypes>[]> {
return (await XMTPModule.listGroups(client.inboxId)).map((json: string) => {
return new Group(client, JSON.parse(json))
const group = JSON.parse(json)
const members = group['members'].map((mem: string) => {
return Member.from(mem)
})
return new Group(client, group, members)
})
}

Expand Down Expand Up @@ -309,8 +316,12 @@ export async function findGroup<
client: Client<ContentTypes>,
groupId: string
): Promise<Group<ContentTypes> | undefined> {
const group = await XMTPModule.findGroup(client.inboxId, groupId)
return new Group(client, JSON.parse(group))
const json = await XMTPModule.findGroup(client.inboxId, groupId)
const group = JSON.parse(json)
const members = group['members'].map((mem: string) => {
return Member.from(mem)
})
return new Group(client, group, members)
}

export async function findV3Message<
Expand Down Expand Up @@ -567,7 +578,10 @@ export async function listAll<
return list.map((json: string) => {
const jsonObj = JSON.parse(json)
if (jsonObj.version === ConversationVersion.GROUP) {
return new Group(client, jsonObj)
const members = jsonObj.members.map((mem: string) => {
return Member.from(mem)
})
return new Group(client, jsonObj, members)
} else {
return new Conversation(client, jsonObj)
}
Expand Down Expand Up @@ -1146,7 +1160,11 @@ export async function processWelcomeMessage<
client.inboxId,
encryptedMessage
)
return new Group(client, JSON.parse(json))
const group = JSON.parse(json)
const members = group['members'].map((mem: string) => {
return Member.from(mem)
})
return new Group(client, group, members)
}

export async function exportNativeLogs() {
Expand Down
14 changes: 12 additions & 2 deletions src/lib/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from './ConversationContainer'
import { DecodedMessage } from './DecodedMessage'
import { Group, GroupParams } from './Group'
import { Member } from './Member'
import { CreateGroupOptions } from './types/CreateGroupOptions'
import { EventTypes } from './types/EventTypes'
import { PermissionPolicySet } from './types/PermissionPolicySet'
Expand Down Expand Up @@ -149,7 +150,10 @@ export default class Conversations<
return
}
this.known[group.id] = true
await callback(new Group(this.client, group))
const members = group['members'].map((mem: string) => {
return Member.from(mem)
})
await callback(new Group(this.client, group, members))
}
)
this.subscriptions[EventTypes.Group] = groupsSubscription
Expand Down Expand Up @@ -286,10 +290,16 @@ export default class Conversations<

this.known[conversationContainer.topic] = true
if (conversationContainer.version === ConversationVersion.GROUP) {
const members = conversationContainer['members'].map(
(mem: string) => {
return Member.from(mem)
}
)
return await callback(
new Group(
this.client,
conversationContainer as unknown as GroupParams
conversationContainer as unknown as GroupParams,
members
)
)
} else {
Expand Down
Loading
Loading