Skip to content

Commit

Permalink
Merge pull request #632 from xmtp/rygine/latest-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine authored Jun 15, 2024
2 parents 6c2474c + a419052 commit 5b5ff96
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-buckets-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/mls-client": patch
---

Upgrade to latest node bindings
2 changes: 1 addition & 1 deletion packages/mls-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"dependencies": {
"@xmtp/content-type-primitives": "^1.0.1",
"@xmtp/content-type-text": "^1.0.0",
"@xmtp/mls-client-bindings-node": "^0.0.4",
"@xmtp/mls-client-bindings-node": "^0.0.5",
"@xmtp/proto": "^3.61.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/mls-client/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ export class Client {
this.#innerClient.addEcdsaSignature(signatureBytes)
}

addErc1271Signature(
addScwSignature(
signatureBytes: Uint8Array,
chainId: string,
accountAddress: string,
chainRpcUrl: string,
blockNumber: bigint
) {
this.#innerClient.addErc1271Signature(
this.#innerClient.addScwSignature(
signatureBytes,
chainId,
accountAddress,
Expand Down
14 changes: 14 additions & 0 deletions packages/mls-client/src/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export class Conversation {
return this.#group.updateGroupName(name)
}

get imageUrl() {
return this.#group.groupImageUrlSquare()
}

async updateImageUrl(imageUrl: string) {
return this.#group.updateGroupImageUrlSquare(imageUrl)
}

get isActive() {
return this.#group.isActive()
}
Expand Down Expand Up @@ -65,6 +73,12 @@ export class Conversation {
return this.#group.superAdminList()
}

get permissions() {
return {
policyType: this.#group.groupPermissions().policyType(),
}
}

isAdmin(inboxId: string) {
return this.#group.isAdmin(inboxId)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/mls-client/src/Conversations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
GroupPermissions,
NapiConversations,
NapiCreateGroupOptions,
NapiListMessagesOptions,
} from '@xmtp/mls-client-bindings-node'
import { AsyncStream, type StreamCallback } from '@/AsyncStream'
Expand All @@ -25,11 +25,11 @@ export class Conversations {

async newConversation(
accountAddresses: string[],
permissions?: GroupPermissions
options?: NapiCreateGroupOptions
) {
const group = await this.#conversations.createGroup(
accountAddresses,
permissions
options
)
const conversation = new Conversation(this.#client, group)
this.#map.set(conversation.id, conversation)
Expand Down
1 change: 1 addition & 0 deletions packages/mls-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export {
GroupUpdatedCodec,
} from './codecs/GroupUpdatedCodec'
export type { StreamCallback } from './AsyncStream'
export { GroupPermissions } from '@xmtp/mls-client-bindings-node'
26 changes: 26 additions & 0 deletions packages/mls-client/test/Conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ describe('Conversation', () => {
expect(conversation2.messages().length).toBe(1)
})

it('should update conversation image URL', async () => {
const user1 = createUser()
const user2 = createUser()
const client1 = await createRegisteredClient(user1)
const client2 = await createRegisteredClient(user2)
const conversation = await client1.conversations.newConversation([
user2.account.address,
])
const imageUrl = 'https://foo/bar.jpg'
await conversation.updateImageUrl(imageUrl)
expect(conversation.imageUrl).toBe(imageUrl)
const messages = conversation.messages()
expect(messages.length).toBe(2)

await client2.conversations.sync()
const conversations = await client2.conversations.list()
expect(conversations.length).toBe(1)

const conversation2 = conversations[0]
expect(conversation2).toBeDefined()
await conversation2.sync()
expect(conversation2.id).toBe(conversation.id)
expect(conversation2.imageUrl).toBe(imageUrl)
expect(conversation2.messages().length).toBe(1)
})

it('should add and remove members', async () => {
const user1 = createUser()
const user2 = createUser()
Expand Down
58 changes: 58 additions & 0 deletions packages/mls-client/test/Conversations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContentTypeText } from '@xmtp/content-type-text'
import { GroupPermissions } from '@xmtp/mls-client-bindings-node'
import { describe, expect, it } from 'vitest'
import { createRegisteredClient, createUser } from '@test/helpers'

Expand All @@ -25,6 +26,9 @@ describe('Conversations', () => {
expect(conversation.createdAtNs).toBeDefined()
expect(conversation.isActive).toBe(true)
expect(conversation.name).toBe('')
expect(conversation.permissions.policyType).toBe(
GroupPermissions.EveryoneIsAdmin
)
expect(conversation.addedByInboxId).toBe(client1.inboxId)
expect(conversation.messages().length).toBe(1)
expect(conversation.members.length).toBe(2)
Expand All @@ -49,6 +53,60 @@ describe('Conversations', () => {
expect(conversations2[0].id).toBe(conversation.id)
})

it('should create a new conversation with options', async () => {
const user1 = createUser()
const user2 = createUser()
const user3 = createUser()
const user4 = createUser()
const user5 = createUser()
const client1 = await createRegisteredClient(user1)
await createRegisteredClient(user2)
await createRegisteredClient(user3)
await createRegisteredClient(user4)
await createRegisteredClient(user5)
const groupWithName = await client1.conversations.newConversation(
[user2.account.address],
{
groupName: 'foo',
}
)
expect(groupWithName).toBeDefined()
expect(groupWithName.name).toBe('foo')
expect(groupWithName.imageUrl).toBe('')

const groupWithImageUrl = await client1.conversations.newConversation(
[user3.account.address],
{
groupImageUrlSquare: 'https://foo/bar.png',
}
)
expect(groupWithImageUrl).toBeDefined()
expect(groupWithImageUrl.name).toBe('')
expect(groupWithImageUrl.imageUrl).toBe('https://foo/bar.png')

const groupWithNameAndImageUrl =
await client1.conversations.newConversation([user4.account.address], {
groupImageUrlSquare: 'https://foo/bar.png',
groupName: 'foo',
})
expect(groupWithNameAndImageUrl).toBeDefined()
expect(groupWithNameAndImageUrl.name).toBe('foo')
expect(groupWithNameAndImageUrl.imageUrl).toBe('https://foo/bar.png')

const groupWithPermissions = await client1.conversations.newConversation(
[user4.account.address],
{
permissions: GroupPermissions.GroupCreatorIsAdmin,
}
)
expect(groupWithPermissions).toBeDefined()
expect(groupWithPermissions.name).toBe('')
expect(groupWithPermissions.imageUrl).toBe('')
expect(groupWithPermissions.permissions.policyType).toBe(
GroupPermissions.GroupCreatorIsAdmin
)
})

it('should stream new conversations', async () => {
const user1 = createUser()
const user2 = createUser()
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2881,10 +2881,10 @@ __metadata:
languageName: node
linkType: hard

"@xmtp/mls-client-bindings-node@npm:^0.0.4":
version: 0.0.4
resolution: "@xmtp/mls-client-bindings-node@npm:0.0.4"
checksum: 10/508839e57a7126f8f2d9898c62c117cd2626279c244b57c2a257bb7681755e19bde985df4a666c61b665b7bb23b9aa8d784527c601797845271c1cf61af26808
"@xmtp/mls-client-bindings-node@npm:^0.0.5":
version: 0.0.5
resolution: "@xmtp/mls-client-bindings-node@npm:0.0.5"
checksum: 10/b00582aec3e328106dc8fb95ef2e637d591c91ef7b9b4c8e1f84d8f5323794f3b36ccd96ded5f65390a37ea40203582b6cdb379d60f6d59fa3128c37661110d7
languageName: node
linkType: hard

Expand All @@ -2901,7 +2901,7 @@ __metadata:
"@vitest/coverage-v8": "npm:^1.6.0"
"@xmtp/content-type-primitives": "npm:^1.0.1"
"@xmtp/content-type-text": "npm:^1.0.0"
"@xmtp/mls-client-bindings-node": "npm:^0.0.4"
"@xmtp/mls-client-bindings-node": "npm:^0.0.5"
"@xmtp/proto": "npm:^3.61.1"
"@xmtp/xmtp-js": "workspace:^"
eslint: "npm:^8.57.0"
Expand Down

0 comments on commit 5b5ff96

Please sign in to comment.