@xmtp/content-type-reply
Version:
An XMTP content type to support replying to a message
3 lines (2 loc) • 1.18 kB
JavaScript
import{ContentTypeId as e}from"@xmtp/content-type-primitives";import{content as n}from"@xmtp/proto";const t=new e({authorityId:"xmtp.org",typeId:"reply",versionMajor:1,versionMinor:0});class r{get contentType(){return t}encode(e,t){const r=t.codecFor(e.contentType);if(!r)throw new Error(`missing codec for content type "${e.contentType.toString()}"`);const o=r.encode(e.content,t),c=n.EncodedContent.encode(o).finish(),i={contentType:e.contentType.toString(),reference:e.reference};return e.referenceInboxId&&(i.referenceInboxId=e.referenceInboxId),{type:this.contentType,parameters:i,content:c}}decode(t,r){const o=n.EncodedContent.decode(t.content);if(!o.type)throw new Error("missing content type");const c=new e(o.type),i=r.codecFor(c);if(!i)throw new Error(`missing codec for content type "${c.toString()}"`);return{reference:t.parameters.reference,referenceInboxId:t.parameters.referenceInboxId,contentType:c,content:i.decode(o,r)}}fallback(e){return"string"==typeof e.content?`Replied with “${e.content}” to an earlier message`:"Replied to an earlier message"}shouldPush(){return!0}}export{t as ContentTypeReply,r as ReplyCodec};
//# sourceMappingURL=index.js.map