Skip to content

Commit 3b23812

Browse files
authored
fix: keep rendered message media counts consistent (#117850)
1 parent fcaa9d4 commit 3b23812

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createRenderedMessageBatchPlan } from "./rendered-batch.js";
3+
4+
describe("createRenderedMessageBatchPlan", () => {
5+
it("keeps aggregate media counts aligned with normalized media items", () => {
6+
const plan = createRenderedMessageBatchPlan([
7+
{
8+
text: "caption",
9+
mediaUrls: [" ", "/tmp/image.png", "\t"],
10+
audioAsVoice: true,
11+
},
12+
]);
13+
14+
expect(plan.mediaCount).toBe(1);
15+
expect(plan.voiceCount).toBe(1);
16+
expect(plan.items[0]).toMatchObject({
17+
kinds: ["text", "voice"],
18+
mediaUrls: ["/tmp/image.png"],
19+
audioAsVoice: true,
20+
});
21+
});
22+
});

‎src/channels/message/rendered-batch.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
} from "./types.js";
1313

1414
function countMedia(payload: ReplyPayload): number {
15-
return (payload.mediaUrls?.filter(Boolean).length ?? 0) + (payload.mediaUrl ? 1 : 0);
15+
return collectMediaUrls(payload).length;
1616
}
1717

1818
function collectMediaUrls(payload: ReplyPayload): string[] {

0 commit comments

Comments
 (0)