Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from xmtp/rygine/reaction-update
Browse files Browse the repository at this point in the history
Add schema to Reaction content type
  • Loading branch information
rygine authored Jul 14, 2023
2 parents 0d300a6 + 08ce15d commit 616a28b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/light-kids-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/content-type-reaction": patch
---

Add schema to Reaction content type
2 changes: 2 additions & 0 deletions packages/content-type-reaction/src/Reaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("ReactionContentType", () => {
action: "added",
content: "smile",
reference: originalMessage.id,
schema: "shortcode",
};

await conversation.send(reaction, { contentType: ContentTypeReaction });
Expand All @@ -48,5 +49,6 @@ describe("ReactionContentType", () => {
expect(messageContent.action).toBe("added");
expect(messageContent.content).toBe("smile");
expect(messageContent.reference).toBe(originalMessage.id);
expect(messageContent.schema).toBe("shortcode");
});
});
11 changes: 10 additions & 1 deletion packages/content-type-reaction/src/Reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ export type Reaction = {
* The content of the reaction
*/
content: string;
/**
* The schema of the content to provide guidance on how to display it
*/
schema: "unicode" | "shortcode" | "custom";
};

export type ReactionParameters = Pick<Reaction, "action" | "reference"> & {
export type ReactionParameters = Pick<
Reaction,
"action" | "reference" | "schema"
> & {
encoding: "UTF-8";
};

Expand All @@ -39,6 +46,7 @@ export class ReactionCodec implements ContentCodec<Reaction> {
encoding: "UTF-8",
action: content.action,
reference: content.reference,
schema: content.schema,
},
content: new TextEncoder().encode(content.content),
};
Expand All @@ -52,6 +60,7 @@ export class ReactionCodec implements ContentCodec<Reaction> {
return {
action: content.parameters.action,
reference: content.parameters.reference,
schema: content.parameters.schema,
content: new TextDecoder().decode(content.content),
};
}
Expand Down

0 comments on commit 616a28b

Please sign in to comment.