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

Bug streaming groups multi client #496

Merged
merged 5 commits into from
Sep 20, 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
60 changes: 60 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,29 @@ test('can stream all groups and conversations', async () => {
return true
})

test('can stream groups and messages', async () => {
const [alixClient, boClient] = await createClients(2)

// Start streaming groups
const groups: Group<any>[] = []
await alixClient.conversations.streamGroups(async (group: Group<any>) => {
groups.push(group)
})
// Stream messages twice
await alixClient.conversations.streamAllMessages(async (message) => {}, true)
await alixClient.conversations.streamAllMessages(async (message) => {}, true)

// bo creates a group with alix so a stream callback is fired
// eslint-disable-next-line @typescript-eslint/no-unused-vars
await boClient.conversations.newGroup([alixClient.address])
await delayToPropogate()
if ((groups.length as number) !== 1) {
throw Error(`Unexpected num groups (should be 1): ${groups.length}`)
}

return true
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nmalzieu I think this fix also fixed this weird bug? Can you confirm?


test('canMessage', async () => {
const [bo, alix, caro] = await createClients(3)

Expand Down Expand Up @@ -2261,6 +2284,43 @@ test('can sync all groups', async () => {
return true
})

test('only streams groups that can be decrypted', async () => {
// Create three MLS enabled Clients
const [alixClient, boClient, caroClient] = await createClients(3)
const alixGroups: Group<any>[] = []
const boGroups: Group<any>[] = []
const caroGroups: Group<any>[] = []

await alixClient.conversations.streamGroups(async (group: Group<any>) => {
alixGroups.push(group)
})
await boClient.conversations.streamGroups(async (group: Group<any>) => {
boGroups.push(group)
})
await caroClient.conversations.streamGroups(async (group: Group<any>) => {
caroGroups.push(group)
})

await alixClient.conversations.newGroup([boClient.address])

assert(
alixGroups.length === 1,
`alix group length should be 1 but was ${alixGroups.length}`
)

assert(
boGroups.length === 1,
`bo group length should be 1 but was ${boGroups.length}`
)

assert(
caroGroups.length !== 1,
`caro group length should be 0 but was ${caroGroups.length}`
)

return true
})

// 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
2 changes: 1 addition & 1 deletion src/lib/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class Conversations<
const groupsSubscription = XMTPModule.emitter.addListener(
EventTypes.Group,
async ({ inboxId, group }: { inboxId: string; group: GroupParams }) => {
if (this.known[group.id]) {
if (this.known[group.id] || this.client.inboxId !== inboxId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good fix to merge now.

long term, I wonder if it would be a worthwhile performance gain to programmatically generate these Expo Module events to include the inbox-id in their name, so we dont send copies of all clients' events to each client event listener and then need to filter them out.

Events(
// Auth
"sign",
"authed",
"preCreateIdentityCallback",
"preEnableIdentityCallback",
"preAuthenticateToInboxCallback",
// Conversations
"conversation",
"group",
"conversationContainer",
"message",
"allGroupMessage",
// Conversation
"conversationMessage",
// Group
"groupMessage",
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into that and it didn't seem straight forward. But something we should consider looking into again for sure.

return
}
this.known[group.id] = true
Expand Down
Loading