Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ function getForExpenseMovedFromSelfDM(translate: LocalizedTranslate, destination
// - A 1:1 DM
const currentUserAccountID = getPersonalDetailByEmail(currentUserLogin)?.accountID;
const reportName = isPolicyExpenseChat(rootParentReport)
? getPolicyExpenseChatName({report: rootParentReport})
: buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID});
? getPolicyExpenseChatName({report: rootParentReport, translate})
: buildReportNameFromParticipantNames({report: rootParentReport, currentUserAccountID, translate});
const policyName = getPolicyName({report: rootParentReport, returnEmptyIfNotFound: true, policy});
// If we can't determine either the report name or policy name, return the default message
if (isEmpty(policyName) && !reportName) {
Expand Down
29 changes: 21 additions & 8 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ const buildReportNameFromParticipantNames = ({
report,
personalDetailsList: personalDetailsData,
currentUserAccountID,
translate,
}: {
report: OnyxEntry<Report>;
personalDetailsList?: Partial<PersonalDetailsList>;
currentUserAccountID?: number;
translate: LocalizedTranslate;
}) =>
Object.keys(report?.participants ?? {})
.map(Number)
Expand All @@ -232,6 +234,7 @@ const buildReportNameFromParticipantNames = ({
shouldUseShortForm: true,
personalDetailsData,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
translate,
}),
}))
.filter((participant) => participant.name)
Expand All @@ -242,6 +245,7 @@ const buildReportNameFromParticipantNames = ({
accountID,
personalDetailsData,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
translate,
});
}
return formattedNames ? `${formattedNames}, ${name}` : name;
Expand All @@ -260,6 +264,7 @@ const customCollator = new Intl.Collator('en', {usage: 'sort', sensitivity: 'var
*/
function getGroupChatName(
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
translate: LocalizedTranslate,
participants?: SelectedParticipant[],
shouldApplyLimit = false,
report?: OnyxEntry<Report>,
Expand Down Expand Up @@ -290,7 +295,7 @@ function getGroupChatName(
return participantAccountIDs
.map(
(participantAccountID, index) =>
getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber}) ||
getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber, translate}) ||
formatPhoneNumber(participants?.[index]?.login ?? ''),
)
.sort((first, second) => customCollator.compare(first ?? '', second ?? ''))
Expand All @@ -299,21 +304,29 @@ function getGroupChatName(
.slice(0, CONST.REPORT_NAME_LIMIT)
.concat(shouldAddEllipsis ? '...' : '');
}
return translateLocal('groupChat.defaultReportName', getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber}));
return translate('groupChat.defaultReportName', getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber, translate}));
}

/**
* Get the title for a policy expense chat
*/
function getPolicyExpenseChatName({report, personalDetailsList}: {report: OnyxEntry<Report>; personalDetailsList?: Partial<PersonalDetailsList>}): string | undefined {
function getPolicyExpenseChatName({
report,
personalDetailsList,
translate,
}: {
report: OnyxEntry<Report>;
personalDetailsList?: Partial<PersonalDetailsList>;
translate: LocalizedTranslate;
}): string | undefined {
const ownerAccountID = report?.ownerAccountID;
const personalDetails = ownerAccountID ? personalDetailsList?.[ownerAccountID] : undefined;
const login = personalDetails ? personalDetails.login : null;

const reportOwnerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber: formatPhoneNumberPhoneUtils}) || login;
const reportOwnerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) || login;

if (reportOwnerDisplayName) {
return translateLocal('workspace.common.policyExpenseChatName', reportOwnerDisplayName);
return translate('workspace.common.policyExpenseChatName', reportOwnerDisplayName);
}

return report?.reportName;
Expand Down Expand Up @@ -1033,7 +1046,7 @@ function computeReportName({
}

if (isGroupChat(report)) {
return getGroupChatName(formatPhoneNumberPhoneUtils, undefined, true, report) ?? '';
return getGroupChatName(formatPhoneNumberPhoneUtils, translate, undefined, true, report) ?? '';
}

let formattedName: string | undefined;
Expand All @@ -1043,7 +1056,7 @@ function computeReportName({
}

if (isPolicyExpenseChat(report)) {
formattedName = getPolicyExpenseChatName({report, personalDetailsList});
formattedName = getPolicyExpenseChatName({report, personalDetailsList, translate});
}

const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
Expand Down Expand Up @@ -1093,7 +1106,7 @@ function computeReportName({
}

// Not a room or PolicyExpenseChat, generate title from first 5 other participants
formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, currentUserAccountID});
formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, currentUserAccountID, translate});

const finalName = formattedName ?? report?.reportName ?? '';

Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3941,7 +3941,7 @@ function getIconsForIOUReport(report: OnyxInputOrEntry<Report>, personalDetails:
/**
* Helper function to get the icons for a group chat. Only to be used in getIcons().
*/
function getIconsForGroupChat(report: OnyxInputOrEntry<Report>, formatPhoneNumber: LocaleContextProps['formatPhoneNumber']): Icon[] {
function getIconsForGroupChat(report: OnyxInputOrEntry<Report>, formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], translate: LocalizedTranslate): Icon[] {
if (!report) {
return [];
}
Expand All @@ -3950,7 +3950,7 @@ function getIconsForGroupChat(report: OnyxInputOrEntry<Report>, formatPhoneNumbe
source: report.avatarUrl || getDefaultGroupAvatar(report.reportID),
id: -1,
type: CONST.ICON_TYPE_AVATAR,
name: getGroupChatName(formatPhoneNumber, undefined, true, report),
name: getGroupChatName(formatPhoneNumber, translate, undefined, true, report),
};
return [groupChatIcon];
}
Expand Down Expand Up @@ -4074,7 +4074,7 @@ function getIcons(
return getIconsForParticipants([CONST.ACCOUNT_ID.NOTIFICATIONS ?? 0], personalDetails);
}
if (isGroupChat(report)) {
return getIconsForGroupChat(report, formatPhoneNumber);
return getIconsForGroupChat(report, formatPhoneNumber, translate);
}
if (isOneOnOneChat(report)) {
const otherParticipantsAccountIDs = Object.keys(report.participants ?? {})
Expand Down
2 changes: 1 addition & 1 deletion src/pages/DynamicReportParticipantsInvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function DynamicReportParticipantsInvitePage({report}: DynamicReportParticipants
toggleSelection(option);
};

const reportName = getGroupChatName(formatPhoneNumber, undefined, true, report);
const reportName = getGroupChatName(formatPhoneNumber, translate, undefined, true, report);

const goBack = () => {
Navigation.goBack(backPath);
Expand Down
4 changes: 3 additions & 1 deletion src/pages/GroupChatNameEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) {
const {translate, formatPhoneNumber} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();

const existingReportName = report ? getGroupChatName(formatPhoneNumber, undefined, false, report) : getGroupChatName(formatPhoneNumber, groupChatDraft?.participants);
const existingReportName = report
? getGroupChatName(formatPhoneNumber, translate, undefined, false, report)
: getGroupChatName(formatPhoneNumber, translate, groupChatDraft?.participants);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName;

Expand Down
2 changes: 1 addition & 1 deletion src/pages/NewChatConfirmPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function AvatarAndGroupNameSection({setAvatarFile, optimisticReportID}: AvatarAn
const [newGroupDraft, newGroupDraftMetaData] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT);

const icons = useMemoizedLazyExpensifyIcons(['Camera']);
const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(formatPhoneNumber, newGroupDraft?.participants);
const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(formatPhoneNumber, translate, newGroupDraft?.participants);

const stashedLocalAvatarImage = newGroupDraft?.avatarUri;

Expand Down
Loading
Loading