Skip to content

Commit

Permalink
Use Conversation#send instead of new method for sending with custom c…
Browse files Browse the repository at this point in the history
…ontent types
  • Loading branch information
nakajima committed Nov 30, 2023
1 parent caee68c commit 3b69fb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ test('register and use custom content types', async () => {
const bobConvo = await bob.conversations.newConversation(alice.address)
const aliceConvo = await alice.conversations.newConversation(bob.address)

await bobConvo.sendWithJSCodec(12, ContentTypeNumber)
await bobConvo.send(12, { contentType: ContentTypeNumber })

const messages = await aliceConvo.messages()
assert(messages.length === 1, 'did not get messages')
Expand Down
13 changes: 11 additions & 2 deletions src/lib/Conversation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { DecodedMessage } from './DecodedMessage'
import * as XMTP from '../index'
import { ConversationContext, PreparedLocalMessage } from '../index'

export type SendOptions = {
contentType?: XMTP.ContentTypeId
}

export class Conversation<ContentTypes> {
client: XMTP.Client<ContentTypes>
createdAt: number
Expand Down Expand Up @@ -81,7 +86,7 @@ export class Conversation<ContentTypes> {
}
}

async sendWithJSCodec<T>(
private async _sendWithJSCodec<T>(
content: T,
contentType: XMTP.ContentTypeId
): Promise<string> {
Expand Down Expand Up @@ -111,7 +116,11 @@ export class Conversation<ContentTypes> {
*
* @todo Support specifying a conversation ID in future implementations.
*/
async send(content: any): Promise<string> {
async send(content: any, opts?: SendOptions): Promise<string> {
if (opts && opts.contentType) {
return await this._sendWithJSCodec(content, opts.contentType)
}

try {
if (typeof content === 'string') {
content = { text: content }
Expand Down

0 comments on commit 3b69fb1

Please sign in to comment.