UNPKG

@xmtp/content-type-reaction

Version:

An XMTP content type to support reactions to messages

3 lines (2 loc) 1.02 kB
import{ContentTypeId as e}from"@xmtp/content-type-primitives";const n=new e({authorityId:"xmtp.org",typeId:"reaction",versionMajor:1,versionMinor:0});class t{get contentType(){return n}encode(e){const{action:n,reference:t,referenceInboxId:r,schema:c,content:o}=e;return{type:this.contentType,parameters:{},content:(new TextEncoder).encode(JSON.stringify({action:n,reference:t,referenceInboxId:r,schema:c,content:o}))}}decode(e){const n=(new TextDecoder).decode(e.content);try{const e=JSON.parse(n),{action:t,reference:r,referenceInboxId:c,schema:o,content:a}=e;return{action:t,reference:r,referenceInboxId:c,schema:o,content:a}}catch{}const t=e.parameters;return{action:t.action,reference:t.reference,schema:t.schema,content:n}}fallback(e){switch(e.action){case"added":return`Reacted “${e.content}” to an earlier message`;case"removed":return`Removed “${e.content}” from an earlier message`;default:return}}shouldPush(){return!1}}export{n as ContentTypeReaction,t as ReactionCodec}; //# sourceMappingURL=index.js.map