fix: keep contact summary counts (#625) (thanks @mahmoudashraf93)

This commit is contained in:
Peter Steinberger
2026-01-10 01:02:28 +01:00
parent d1e10af1e1
commit 103dd3af64
2 changed files with 27 additions and 2 deletions

View File

@@ -124,10 +124,32 @@ describe("web inbound helpers", () => {
},
} as unknown as import("@whiskeysockets/baileys").proto.IMessage);
expect(body).toBe(
"<contacts: Alice, +15555550101, Bob, +15555550102, Charlie, +15555550103 (+1 more), Dana, +15555550105>",
"<contacts: Alice, +15555550101, Bob, +15555550102, Charlie, +15555550103 (+1 more) +1 more>",
);
});
it("counts empty WhatsApp contact cards in array summaries", () => {
const body = extractText({
contactsArrayMessage: {
contacts: [
{
displayName: "Alice",
vcard: [
"BEGIN:VCARD",
"VERSION:3.0",
"FN:Alice",
"TEL;TYPE=CELL:+15555550101",
"END:VCARD",
].join("\n"),
},
{},
{},
],
},
} as unknown as import("@whiskeysockets/baileys").proto.IMessage);
expect(body).toBe("<contacts: Alice, +15555550101 +2 more>");
});
it("summarizes empty WhatsApp contact cards with a count", () => {
const body = extractText({
contactsArrayMessage: {

View File

@@ -801,7 +801,10 @@ function formatContactsPlaceholder(labels: string[], total: number): string {
const suffix = total === 1 ? "contact" : "contacts";
return `<contacts: ${total} ${suffix}>`;
}
return `<contacts: ${cleaned.join(", ")}>`;
const shown = cleaned.slice(0, 3);
const remaining = Math.max(total - shown.length, 0);
const suffix = remaining > 0 ? ` +${remaining} more` : "";
return `<contacts: ${shown.join(", ")}${suffix}>`;
}
function formatContactLabel(