Skip to content

Commit 636515a

Browse files
Merge pull request #46703 from nkdengineer/fix/46502
fix: New users are not displayed in group name
2 parents 4d5d0b8 + 6c41a31 commit 636515a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/libs/ReportUtils.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import type {
4343
UserWallet,
4444
} from '@src/types/onyx';
4545
import type {Participant} from '@src/types/onyx/IOU';
46+
import type {SelectedParticipant} from '@src/types/onyx/NewGroupChatDraft';
4647
import type {OriginalMessageExportedToIntegration} from '@src/types/onyx/OldDotAction';
4748
import type Onboarding from '@src/types/onyx/Onboarding';
4849
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
@@ -2136,28 +2137,30 @@ function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants {
21362137
/**
21372138
* Returns the report name if the report is a group chat
21382139
*/
2139-
function getGroupChatName(participantAccountIDs?: number[], shouldApplyLimit = false, report?: OnyxEntry<Report>): string | undefined {
2140+
function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit = false, report?: OnyxEntry<Report>): string | undefined {
21402141
// If we have a report always try to get the name from the report.
21412142
if (report?.reportName) {
21422143
return report.reportName;
21432144
}
21442145

2145-
// Get participantAccountIDs from participants object
2146-
let participants = participantAccountIDs ?? Object.keys(report?.participants ?? {}).map(Number);
2146+
let participantAccountIDs = participants?.map((participant) => participant.accountID) ?? Object.keys(report?.participants ?? {}).map(Number);
21472147
if (shouldApplyLimit) {
2148-
participants = participants.slice(0, 5);
2148+
participantAccountIDs = participantAccountIDs.slice(0, 5);
21492149
}
2150-
const isMultipleParticipantReport = participants.length > 1;
2150+
const isMultipleParticipantReport = participantAccountIDs.length > 1;
21512151

21522152
if (isMultipleParticipantReport) {
2153-
return participants
2154-
.map((participant) => getDisplayNameForParticipant(participant, isMultipleParticipantReport))
2153+
return participantAccountIDs
2154+
.map(
2155+
(participantAccountID, index) =>
2156+
getDisplayNameForParticipant(participantAccountID, isMultipleParticipantReport) || LocalePhoneNumber.formatPhoneNumber(participants?.[index]?.login ?? ''),
2157+
)
21552158
.sort((first, second) => localeCompare(first ?? '', second ?? ''))
21562159
.filter(Boolean)
21572160
.join(', ');
21582161
}
21592162

2160-
return Localize.translateLocal('groupChat.defaultReportName', {displayName: getDisplayNameForParticipant(participants[0], false)});
2163+
return Localize.translateLocal('groupChat.defaultReportName', {displayName: getDisplayNameForParticipant(participantAccountIDs[0], false)});
21612164
}
21622165

21632166
function getParticipants(reportID: string) {

src/pages/GroupChatNameEditPage.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPagePr
4444
const {translate} = useLocalize();
4545
const {inputCallbackRef} = useAutoFocusInput();
4646

47-
// We will try to get the chatName from the report or draft depending on what flow we are in
48-
const draftParticipantAccountIDs = useMemo(() => (groupChatDraft?.participants ?? []).map((participant) => participant.accountID), [groupChatDraft?.participants]);
4947
const existingReportName = useMemo(
50-
() => (report ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getGroupChatName(draftParticipantAccountIDs)),
51-
[draftParticipantAccountIDs, report],
48+
() => (report ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getGroupChatName(groupChatDraft?.participants)),
49+
[groupChatDraft?.participants, report],
5250
);
5351
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
5452
const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName;

src/pages/NewChatConfirmPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
5050
const {translate} = useLocalize();
5151
const styles = useThemeStyles();
5252
const personalData = useCurrentUserPersonalDetails();
53-
const participantAccountIDs = (newGroupDraft?.participants ?? []).map((participant) => participant.accountID);
5453
const selectedOptions = useMemo((): Participant[] => {
5554
if (!newGroupDraft?.participants) {
5655
return [];
@@ -61,7 +60,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
6160
return options;
6261
}, [allPersonalDetails, newGroupDraft?.participants]);
6362

64-
const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : ReportUtils.getGroupChatName(participantAccountIDs ?? []);
63+
const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : ReportUtils.getGroupChatName(newGroupDraft?.participants);
6564
const sections: ListItem[] = useMemo(
6665
() =>
6766
selectedOptions

0 commit comments

Comments
 (0)