diff --git a/example/src/types/typeTests.ts b/example/src/types/typeTests.ts index e8ae52ed5..12afb9608 100644 --- a/example/src/types/typeTests.ts +++ b/example/src/types/typeTests.ts @@ -5,6 +5,7 @@ import { EncodedContent, JSContentCodec, ReactionCodec, + ReplyCodec, TextCodec, sendMessage, } from 'xmtp-react-native-sdk' @@ -177,4 +178,60 @@ export const typeTests = async () => { // @ts-expect-error test: 'test', }) + const supportedReplyCodecs = [...supportedCodecs, new ReplyCodec()] + const replyClient = await Client.createRandom({ + codecs: supportedReplyCodecs, + }) + + const replyConvo = (await replyClient.conversations.list())[0] + await replyConvo.send({ + reaction: { + action: 'added', + content: '💖', + reference: '123', + schema: 'unicode', + }, + }) + await replyConvo.send({ + reply: { + reference: '123', + content: { + reaction: { + action: 'added', + content: '💖', + reference: '123', + schema: 'unicode', + }, + }, + }, + }) + await replyConvo.send({ + reply: { + reference: '123', + content: { + // @ts-expect-error + reaction: { + action: 'added', + content: '💖', + reference: '123', + // schema: 'unicode', + }, + }, + }, + }) + const replyMessages = await replyConvo.messages() + const replyContent = replyMessages[0].content() + if (typeof replyContent === 'string') { + // + } else { + const reply = replyContent + // Typecheck for reaction + if (typeof reply.content === 'string') { + } else { + // is a reply of some type + if (reply.content.text !== 'added') { + // + } + } + } } diff --git a/src/lib/NativeCodecs/ReplyCodec.ts b/src/lib/NativeCodecs/ReplyCodec.ts index 060c4244c..a3eba3a51 100644 --- a/src/lib/NativeCodecs/ReplyCodec.ts +++ b/src/lib/NativeCodecs/ReplyCodec.ts @@ -1,17 +1,13 @@ -import { TextCodec } from './TextCodec' import { ContentTypeId, NativeContentCodec, NativeMessageContent, } from '../ContentCodec' -import { DefaultContentTypes } from '../types/DefaultContentType' -export type ReplyContent< - ContentTypes extends DefaultContentTypes = DefaultContentTypes, -> = { +export type ReplyContent = { reference: string - content: [...ContentTypes, TextCodec][number] | string - contentType: string + // Right now this will assume any NativeMessageContent is valid, but really should only be the supported content types + content: NativeMessageContent } export class ReplyCodec implements NativeContentCodec { diff --git a/src/lib/types/ContentCodec.ts b/src/lib/types/ContentCodec.ts index a869931ed..4b016bc59 100644 --- a/src/lib/types/ContentCodec.ts +++ b/src/lib/types/ContentCodec.ts @@ -11,8 +11,7 @@ export type ReadReceiptContent = object export type ReplyContent = { reference: string - content: any - contentType: string + content: NativeMessageContent } export type ReactionContent = {