Skip to content

Commit

Permalink
Merge pull request #618 from xmtp/rygine/msg-convo
Browse files Browse the repository at this point in the history
Add conversation reference to messages
  • Loading branch information
rygine authored Jun 7, 2024
2 parents ae64690 + 617b3bf commit e0dbc98
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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

0 comments on commit e0dbc98

Please sign in to comment.