Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): title an unnamed chat by its formatted number

Yudhi Armyndharis81f8e30a289c
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index 209bb19a1..d96b0d27e 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -621,7 +621,7 @@ for (const reactStrictMode of [false, true]) {
fetchCalls.some(c => c.method === 'GET' && c.path === `/api/sessions/${SESSION.id}/contacts/check/15550009999`),
'the number was not checked with the gateway',
);
- await within(container.querySelector('.room-header') as HTMLElement).findByText('15550009999');
+ await within(container.querySelector('.room-header') as HTMLElement).findByText('+1 555 000 9999');
assert.ok(!container.querySelector('.new-chat-panel'), 'the panel stayed open over the list');
});
}
@@ -643,6 +643,48 @@ test('the New chat search clear button returns focus to the field it cleared', a
assert.equal(document.activeElement === field, true, `focus is on "${focusedName()}", not on the field`);
});
+test('an unnamed chat is titled by its number, formatted and isolated left to right, in the header and the panel', async () => {
+ const { screen, fireEvent, waitFor, within } = rtl;
+ aliceNow.name = '';
+ const { container } = renderPage();
+ fireEvent.click(await screen.findByText('15550001111'));
+ const title = await waitFor(() => {
+ const name = container.querySelector('.room-header .room-contact-name') as HTMLElement;
+ assert.equal(name?.textContent, '+1 555 000 1111');
+ return name;
+ });
+ assert.equal(title.querySelector('bdi')?.getAttribute('dir'), 'ltr', 'the number in the title is not isolated');
+ assert.equal(container.querySelector('.room-header .room-contact-phone') === null, true, 'the number is shown twice');
+ assert.ok(screen.getByRole('heading', { level: 2, name: '+1 555 000 1111' }), 'the room heading is not the number');
+
+ fireEvent.click(screen.getByRole('button', { name: 'Contact info' }));
+ const panel = await waitFor(() => container.querySelector('.contact-info-panel') as HTMLElement);
+ const heading = within(panel).getByRole('heading', { level: 3 });
+ assert.equal(heading.textContent, '+1 555 000 1111');
+ assert.equal(heading.querySelector('bdi')?.getAttribute('dir'), 'ltr', 'the number in the panel is not isolated');
+ assert.equal(panel.querySelector('.contact-info-sub') === null, true, 'the panel repeats the number under itself');
+});
+
+test('an unnamed privacy-id chat is titled by the number it resolves to, and its own digits are never formatted', async () => {
+ const { screen, fireEvent, waitFor } = rtl;
+ const lid = '262813461250072@lid';
+ Object.assign(aliceNow, { id: lid, name: '' });
+ const title = () => container.querySelector('.room-header .room-contact-name')?.textContent;
+
+ // Unresolved, it keeps the digits of its id as they are: they are no phone number.
+ let { container } = renderPage();
+ fireEvent.click(await screen.findByText('262813461250072'));
+ await waitFor(() => assert.equal(phoneRequests().length, 1, 'the privacy id was not looked up'));
+ await settle();
+ assert.equal(title(), '262813461250072');
+ rtl.cleanup();
+
+ lidPhones[lid] = '15550006666';
+ ({ container } = renderPage());
+ fireEvent.click(await screen.findByText('262813461250072'));
+ await waitFor(() => assert.equal(title(), '+1 555 000 6666'));
+});
+
// ── The number check answers a phone id, while a contact that moved to privacy-id addressing keeps its conversation
// under its @lid: starting a chat with that number has to find it. ──
@@ -690,7 +732,7 @@ test('a privacy-id chat of another phone is not mistaken for the number, which o
await startChatWithTypedNumber();
await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the chat did not open'));
- await within(container.querySelector('.room-header') as HTMLElement).findByText('15550009999');
+ await within(container.querySelector('.room-header') as HTMLElement).findByText('+1 555 000 9999');
assert.equal(listedChatCards(container), before + 1, 'the new chat was not added to the list');
});
@@ -703,7 +745,7 @@ test('a privacy id the engine cannot resolve right now does not stop a chat from
await startChatWithTypedNumber();
await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the chat did not open'));
- await within(container.querySelector('.room-header') as HTMLElement).findByText('15550009999');
+ await within(container.querySelector('.room-header') as HTMLElement).findByText('+1 555 000 9999');
assert.ok(!screen.queryByText('Could not check the number'), 'a failed lookup was shown as a failed number check');
});
@@ -732,7 +774,7 @@ test('an answer about a privacy id that the page cannot read does not stop a cha
await startChatWithTypedNumber();
await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the chat did not open'));
- await within(container.querySelector('.room-header') as HTMLElement).findByText('15550009999');
+ await within(container.querySelector('.room-header') as HTMLElement).findByText('+1 555 000 9999');
assert.ok(!screen.queryByText('Could not check the number'), 'a failed lookup was shown as a failed number check');
});
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index 71abba806..f02512503 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -385,7 +385,11 @@ export function Chats() {
);
const activePhoneText =
activePhoneDisplay ?? (resolvedPhoneQ.data ? formatPhoneForDisplay(resolvedPhoneQ.data) : null);
- const activeChatTitle = activeChat ? activeChat.name || activeChat.id.split('@')[0] : '';
+ // An unnamed chat is titled by its number when one is known, never by the bare digits of its id (a @lid's are no
+ // phone). Shown, that number is isolated left to right, as it is under a name.
+ const activeChatTitle = activeChat ? activeChat.name || activePhoneText || activeChat.id.split('@')[0] : '';
+ const activeChatTitleText =
+ activeChat && !activeChat.name && activePhoneText ? <bdi dir="ltr">{activePhoneText}</bdi> : activeChatTitle;
// The list loaders below reach the translator and the error toast through a ref, not as
// dependencies: both change identity on a language switch, which re-ran the session load (it
@@ -1957,7 +1961,7 @@ export function Chats() {
onImageError={() => activePp.refetch()}
/>
<span className="room-contact-info">
- <span className="room-contact-name">{activeChatTitle}</span>
+ <span className="room-contact-name">{activeChatTitleText}</span>
{/* Personal chats show the prettified phone number — local formatting for
@c.us ids, engine-resolved for @lid privacy ids (which are NOT phones and
must never be formatted as one). Only under a saved name: an unnamed chat's
@@ -2195,16 +2199,19 @@ export function Chats() {
size="lg"
onImageError={() => activePp.refetch()}
/>
- <h3>{activeChatTitle}</h3>
- <p className="contact-info-sub">
- {activePhoneText ? (
- <bdi dir="ltr">{activePhoneText}</bdi>
- ) : activeChat.isGroup ? (
- t('chats.groupSubtitle')
- ) : (
- t('chats.privateContactSubtitle')
- )}
- </p>
+ <h3>{activeChatTitleText}</h3>
+ {/* The number goes under a name only; an unnamed chat's title already is the number. */}
+ {(activeChat.name || !activePhoneText) && (
+ <p className="contact-info-sub">
+ {activePhoneText ? (
+ <bdi dir="ltr">{activePhoneText}</bdi>
+ ) : activeChat.isGroup ? (
+ t('chats.groupSubtitle')
+ ) : (
+ t('chats.privateContactSubtitle')
+ )}
+ </p>
+ )}
<dl className="contact-info-list">
{activePhoneText && (
<>