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 #65 from xmtp/rygine/should-push
Browse files Browse the repository at this point in the history
Add `shouldPush` to all content codecs
  • Loading branch information
rygine authored Mar 12, 2024
2 parents 637c36b + c4d43dc commit cef4d7b
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .changeset/gorgeous-walls-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@xmtp/experimental-content-type-screen-effect": patch
"@xmtp/content-type-reaction": patch
"@xmtp/content-type-read-receipt": patch
"@xmtp/content-type-remote-attachment": patch
"@xmtp/content-type-reply": patch
"@xmtp/content-type-transaction-reference": patch
---

Add `shouldPush` to all content codecs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ describe("ScreenEffectContentType", () => {
expect(messageContent.messageId).toBe(originalMessage.id);
expect(messageContent.effectType).toBe("SNOW");
});

it("has a proper shouldPush value", () => {
const codec = new ScreenEffectCodec();
expect(codec.shouldPush()).toBe(false);
});
});
4 changes: 4 additions & 0 deletions experimental/content-type-screen-effect/src/ScreenEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ export class ScreenEffectCodec
fallback() {
return undefined;
}

shouldPush() {
return false;
}
}
21 changes: 21 additions & 0 deletions packages/content-type-reaction/src/Reaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,25 @@ describe("ReactionContentType", () => {
expect(messageContent.reference).toBe(originalMessage.id);
expect(messageContent.schema).toBe("shortcode");
});

it("has a proper shouldPush value based on content", () => {
const codec = new ReactionCodec();

const addReaction: Reaction = {
action: "added",
content: "smile",
reference: "foo",
schema: "shortcode",
};

const removeReaction: Reaction = {
action: "removed",
content: "smile",
reference: "foo",
schema: "shortcode",
};

expect(codec.shouldPush(addReaction)).toBe(true);
expect(codec.shouldPush(removeReaction)).toBe(false);
});
});
4 changes: 4 additions & 0 deletions packages/content-type-reaction/src/Reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ export class ReactionCodec implements ContentCodec<Reaction> {
return undefined;
}
}

shouldPush(content: Reaction): boolean {
return content.action === "added";
}
}
5 changes: 5 additions & 0 deletions packages/content-type-read-receipt/src/ReadReceipt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ describe("ReadReceiptContentType", () => {
const messageContent = readReceiptMessage.contentType;
expect(messageContent.typeId).toBe("readReceipt");
});

it("has a proper shouldPush value", () => {
const codec = new ReadReceiptCodec();
expect(codec.shouldPush()).toBe(false);
});
});
4 changes: 4 additions & 0 deletions packages/content-type-read-receipt/src/ReadReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ export class ReadReceiptCodec implements ContentCodec<ReadReceipt> {
fallback(content: ReadReceipt): string | undefined {
return undefined;
}

shouldPush() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ test("can send an attachment", async () => {
expect(messageContent.mimeType).toBe("image/png");
expect(messageContent.data).toStrictEqual(Uint8Array.from([5, 4, 3, 2, 1]));
});

test("has a proper shouldPush value", () => {
const codec = new AttachmentCodec();
expect(codec.shouldPush()).toBe(true);
});
4 changes: 4 additions & 0 deletions packages/content-type-remote-attachment/src/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ export class AttachmentCodec implements ContentCodec<Attachment> {
fallback(content: Attachment): string | undefined {
return `Can’t display "${content.filename}". This app doesn’t support attachments.`;
}

shouldPush() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,8 @@ test("fails if content digest does not match", async () => {
RemoteAttachmentCodec.load(message.content as RemoteAttachment, bobClient),
).rejects.toThrow("content digest does not match");
});

test("has a proper shouldPush value", () => {
const codec = new RemoteAttachmentCodec();
expect(codec.shouldPush()).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,8 @@ export class RemoteAttachmentCodec implements ContentCodec<RemoteAttachment> {
fallback(content: RemoteAttachment): string | undefined {
return `Can’t display "${content.filename}". This app doesn’t support attachments.`;
}

shouldPush() {
return true;
}
}
5 changes: 5 additions & 0 deletions packages/content-type-reply/src/Reply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ describe("ReplyContentType", () => {
});
expect(messageContent.reference).toBe(originalMessage.id);
});

it("has a proper shouldPush value", () => {
const codec = new ReplyCodec();
expect(codec.shouldPush()).toBe(true);
});
});
4 changes: 4 additions & 0 deletions packages/content-type-reply/src/Reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ export class ReplyCodec implements ContentCodec<Reply> {
}
return "Replied to an earlier message";
}

shouldPush() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ test("should successfully send and receive a TransactionReference message", asyn
expect(messageContent.reference).toBe(transactionRefToSend.reference);
expect(messageContent.metadata).toEqual(transactionRefToSend.metadata);
});

test("has a proper shouldPush value", () => {
const codec = new TransactionReferenceCodec();
expect(codec.shouldPush()).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ export class TransactionReferenceCodec
}
return `Crypto transaction`;
}

shouldPush() {
return true;
}
}

0 comments on commit cef4d7b

Please sign in to comment.