Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep id-less sends as separate thread bubbles

Yudhi Armyndharis1ad3c47707be
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsx
index 4bdbbd41b..a20b30af4 100644
--- a/dashboard/src/components/chats/ChatComposer.tsx
+++ b/dashboard/src/components/chats/ChatComposer.tsx
@@ -268,11 +268,15 @@ function ChatComposer({
// echo's row via mergeOrAppend instead of just dropping it β€” the echo may carry no media
// payload (a Baileys API send echoes only a marker), so dropping the placeholder would erase
// the attachment's base64 and leave a bare "πŸ“Ž Media" bubble until the next refetch.
+ //
+ // An engine that cannot read the sent id back answers '', which as a key would fold every such
+ // send into one bubble. The row keeps a unique local id instead, without the temp_ prefix: the
+ // gateway did store it, so it counts toward the next page's offset like any other DB row.
const sendKey = messagesQueryKey(selectedSessionId, activeChat.id);
const reconciled: ChatMessageView = {
...tempMessage,
- id: result.messageId,
- waMessageId: result.messageId,
+ id: result.messageId || tempId.replace(/^temp_/, 'sent_'),
+ waMessageId: result.messageId || undefined,
status: 'sent',
};
upsertCachedMessage(queryClient, sendKey, reconciled, { dropId: tempId });
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.ts
index be410eec5..2908e68b0 100644
--- a/dashboard/src/pages/Chats.test.ts
+++ b/dashboard/src/pages/Chats.test.ts
@@ -158,6 +158,9 @@ let sendGate: Promise<void> | null = null;
// Hold Alice's first page open, so a test can write to the thread before it has any data.
let firstPageGate: Promise<void> | null = null;
+// The id a text send answers with. whatsapp-web.js answers '' when it cannot read the sent id back.
+let sendTextId = 'wamid.out.1';
+
function holdSend(): () => void {
let release!: () => void;
sendGate = new Promise<void>(resolve => {
@@ -317,7 +320,7 @@ function installFetchStub(): void {
return Promise.resolve(jsonResponse({ success: true }));
}
if (method === 'POST' && path === `/api/sessions/${SESSION.id}/messages/send-text`) {
- const send = () => jsonResponse({ messageId: 'wamid.out.1', timestamp: 1_700_000_100 });
+ const send = () => jsonResponse({ messageId: sendTextId, timestamp: 1_700_000_100 });
return sendGate ? sendGate.then(send) : Promise.resolve(send());
}
if (method === 'POST' && path === `/api/sessions/${SESSION.id}/messages/send-audio`) {
@@ -383,6 +386,7 @@ afterEach(() => {
olderPageGate = null;
sendGate = null;
firstPageGate = null;
+ sendTextId = 'wamid.out.1';
olderPageFails = false;
chatsResponder = null;
});
@@ -802,6 +806,31 @@ test('text typed with an audio attachment stays in the input instead of showing
assert.equal(within(thread).queryByText('not a caption'), null, 'the audio bubble shows text that was never sent');
});
+test('sends answered with no message id each keep their own bubble', async () => {
+ const { screen, fireEvent, within, waitFor } = rtl;
+ resetFetchCalls();
+ sendTextId = '';
+ const { container } = renderChats();
+
+ await screen.findByText('Main (15551234567)');
+ fireEvent.click(await screen.findByText('Alice'));
+ const thread = container.querySelector('.room-messages') as HTMLElement;
+ await within(thread).findByText('hello from alice');
+
+ const input = screen.getByPlaceholderText('Type a message...') as HTMLInputElement;
+ const sendPath = `/api/sessions/${SESSION.id}/messages/send-text`;
+ for (const [index, text] of ['first id-less', 'second id-less'].entries()) {
+ fireEvent.change(input, { target: { value: text } });
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
+ await waitFor(() => assert.equal(countFetchCalls('POST', sendPath), index + 1));
+ await flush();
+ await flush();
+ }
+
+ assert.ok(within(thread).queryByText('first id-less'), 'the earlier id-less send vanished from the thread');
+ assert.ok(within(thread).queryByText('second id-less'), 'the later id-less send is missing');
+});
+
test('a caption sent with a document shows in its bubble', async () => {
const { screen, fireEvent, within, waitFor } = rtl;
resetFetchCalls();