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

Add conversation reference to messages #618

Merged
merged 4 commits into from
Jun 7, 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
5 changes: 5 additions & 0 deletions .changeset/rude-avocados-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/mls-client": patch
---

Add conversation reference to messages
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions packages/mls-client/src/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Conversation {

stream() {
const asyncStream = new AsyncStream<NapiMessage, DecodedMessage>(
(message) => new DecodedMessage(this.#client, message)
(message) => new DecodedMessage(this.#client, this, message)
)
const stream = this.#group.stream(asyncStream.callback)
asyncStream.stopCallback = stream.end.bind(stream)
Expand Down Expand Up @@ -126,6 +126,6 @@ export class Conversation {
messages(options?: NapiListMessagesOptions): DecodedMessage[] {
return this.#group
.findMessages(options)
.map((message) => new DecodedMessage(this.#client, message))
.map((message) => new DecodedMessage(this.#client, this, message))
}
}
9 changes: 8 additions & 1 deletion packages/mls-client/src/DecodedMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@xmtp/mls-client-bindings-node'
import { ContentTypeId } from '@xmtp/xmtp-js'
import type { Client } from '@/Client'
import type { Conversation } from '@/Conversation'
import { nsToDate } from '@/helpers/date'

export type MessageKind = 'application' | 'membership_change'
Expand All @@ -14,6 +15,7 @@ export class DecodedMessage {
#client: Client
content: any
contentType: ContentTypeId
conversation: Conversation
conversationId: string
deliveryStatus: MessageDeliveryStatus
fallback?: string
Expand All @@ -25,8 +27,13 @@ export class DecodedMessage {
sentAt: Date
sentAtNs: number

constructor(client: Client, message: NapiMessage) {
constructor(
client: Client,
conversation: Conversation,
message: NapiMessage
) {
this.#client = client
this.conversation = conversation
this.id = message.id
this.sentAtNs = message.sentAtNs
this.sentAt = nsToDate(message.sentAtNs)
Expand Down
Loading