Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): isolate an unnamed member's phone in group sentences

Yudhi Armyndharisaee71f8b452c
diff --git a/dashboard/src/components/chats/GroupInfoDialog.tsx b/dashboard/src/components/chats/GroupInfoDialog.tsx
index bd35461cc..1ec958d96 100644
--- a/dashboard/src/components/chats/GroupInfoDialog.tsx
+++ b/dashboard/src/components/chats/GroupInfoDialog.tsx
@@ -348,6 +348,8 @@ function GroupInfoDialog({ session, group, onClose, onRenamed }: GroupInfoDialog
// Formatted from the id, not from `number`: a privacy id (@lid) has digits too, and they are no phone.
const phone = formatPhoneForDisplay(p.id);
const label = own ? t('chats.you') : p.name || phone || p.number;
+ // In a sentence (a button's label, the confirmation) a phone is isolated, as the typed number is.
+ const spoken = !own && !p.name && phone ? isolateNumber(phone) : label;
return (
<li key={p.id}>
<ChatAvatar kind="individual" />
@@ -377,7 +379,7 @@ function GroupInfoDialog({ session, group, onClose, onRenamed }: GroupInfoDialog
)
}
title={p.isAdmin ? t('chats.group.removeAdmin') : t('chats.group.makeAdmin')}
- aria-label={`${p.isAdmin ? t('chats.group.removeAdmin') : t('chats.group.makeAdmin')}: ${label}`}
+ aria-label={`${p.isAdmin ? t('chats.group.removeAdmin') : t('chats.group.makeAdmin')}: ${spoken}`}
>
{p.isAdmin ? <ShieldOff size={16} /> : <ShieldCheck size={16} />}
</button>
@@ -386,13 +388,13 @@ function GroupInfoDialog({ session, group, onClose, onRenamed }: GroupInfoDialog
className="icon-btn small danger"
disabled={pending !== null}
onClick={() => {
- if (!window.confirm(t('chats.group.removeConfirm', { name: label }))) return;
+ if (!window.confirm(t('chats.group.removeConfirm', { name: spoken }))) return;
void runMemberAction(p.id, () =>
sessionApi.removeGroupParticipants(session.id, group.id, [p.id]),
);
}}
title={t('chats.group.remove')}
- aria-label={`${t('chats.group.remove')}: ${label}`}
+ aria-label={`${t('chats.group.remove')}: ${spoken}`}
>
{pending === p.id ? <Loader2 className="animate-spin" size={16} /> : <UserMinus size={16} />}
</button>
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index 544d554d6..d9f686507 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -74,6 +74,8 @@ let groupDescription = 'old description';
let bobIsAdmin = false;
// When true, GROUP also lists a member WhatsApp knows by a privacy id only, which carries no phone number.
let groupHasLidMember = false;
+// When true, the group's second member has no name, so the dialog names it by its phone.
+let bobUnnamed = false;
// Whether the group's info is locked to admins, which decides what a member who is no admin may edit.
let groupLocked = true;
// When true, the session's own account is listed under an id with a device suffix.
@@ -209,7 +211,13 @@ function installFetchStub(): void {
isAdmin: groupAdmin,
isSuperAdmin: false,
},
- { id: '[email protected]', number: '15550002222', name: 'Bob', isAdmin: bobIsAdmin, isSuperAdmin: false },
+ {
+ number: '15550002222',
+ ...(bobUnnamed ? {} : { name: 'Bob' }),
+ isAdmin: bobIsAdmin,
+ isSuperAdmin: false,
+ },
...(groupHasLidMember
? [{ id: '262813461250071@lid', number: '262813461250071', isAdmin: false, isSuperAdmin: false }]
: []),
@@ -392,6 +400,7 @@ afterEach(async () => {
groupDescription = 'old description';
bobIsAdmin = false;
groupHasLidMember = false;
+ bobUnnamed = false;
groupLocked = true;
ownHasDeviceSuffix = false;
refuseMember = false;
@@ -619,6 +628,41 @@ test('the number a check finds unregistered is named inside an isolate in the pa
assert.equal(toast.textContent?.includes(LTR_NUMBER), true, `the toast is not isolated: "${toast.textContent}"`);
});
+// A member with no name is named by a phone, in the member's own button labels and in the remove confirmation.
+const LTR_BOB = `${String.fromCodePoint(0x2066)}+1 555 000 2222${String.fromCodePoint(0x2069)}`;
+
+test('an unnamed member is named inside an isolate in the group dialog button labels', async () => {
+ const { fireEvent, within } = rtl;
+ listGroup = true;
+ bobUnnamed = true;
+ renderPage();
+ const dialog = await openGroupInfo();
+ fireEvent.click(within(dialog).getByRole('tab', { name: 'Participants' }));
+ assert.ok(within(dialog).getByRole('button', { name: `Remove: ${LTR_BOB}` }), 'the remove label is not isolated');
+ assert.ok(within(dialog).getByRole('button', { name: `Make admin: ${LTR_BOB}` }), 'the admin label is not isolated');
+});
+
+test('the remove confirmation names an unnamed member inside an isolate', async () => {
+ const { fireEvent, within } = rtl;
+ listGroup = true;
+ bobUnnamed = true;
+ const confirm = window.confirm;
+ try {
+ renderPage();
+ const dialog = await openGroupInfo();
+ fireEvent.click(within(dialog).getByRole('tab', { name: 'Participants' }));
+ let asked = '';
+ window.confirm = message => {
+ asked = String(message);
+ return false;
+ };
+ fireEvent.click(within(dialog).getByRole('button', { name: /^Remove: / }));
+ assert.equal(asked, `Remove ${LTR_BOB} from the group?`);
+ } finally {
+ window.confirm = confirm;
+ }
+});
+
test('the number a check finds unregistered is named inside an isolate when adding to a group', async () => {
const { screen, fireEvent, within } = rtl;
listGroup = true;