Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: New users are not displayed in group name #46703

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 8 additions & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import type {
UserWallet,
} from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {SelectedParticipant} from '@src/types/onyx/NewGroupChatDraft';
import type {OriginalMessageExportedToIntegration} from '@src/types/onyx/OldDotAction';
import type Onboarding from '@src/types/onyx/Onboarding';
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
Expand Down Expand Up @@ -2016,28 +2017,27 @@ function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants {
/**
* Returns the report name if the report is a group chat
*/
function getGroupChatName(participantAccountIDs?: number[], shouldApplyLimit = false, report?: OnyxEntry<Report>): string | undefined {
function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit = false, report?: OnyxEntry<Report>): string | undefined {
// If we have a report always try to get the name from the report.
if (report?.reportName) {
return report.reportName;
}

// Get participantAccountIDs from participants object
let participants = participantAccountIDs ?? Object.keys(report?.participants ?? {}).map(Number);
let participantAccountIDs = participants?.map((participant) => participant.accountID) ?? Object.keys(report?.participants ?? {}).map(Number);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filter the pending deleted participants to immediately reflect the change in the group name. More details here.

if (shouldApplyLimit) {
participants = participants.slice(0, 5);
participantAccountIDs = participantAccountIDs.slice(0, 5);
}
const isMultipleParticipantReport = participants.length > 1;
const isMultipleParticipantReport = participantAccountIDs.length > 1;

if (isMultipleParticipantReport) {
return participants
.map((participant) => getDisplayNameForParticipant(participant, isMultipleParticipantReport))
return participantAccountIDs
.map((participant, index) => getDisplayNameForParticipant(participant, isMultipleParticipantReport) || LocalePhoneNumber.formatPhoneNumber(participants?.[index]?.login ?? ''))
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
.sort((first, second) => localeCompare(first ?? '', second ?? ''))
.filter(Boolean)
.join(', ');
}

return Localize.translateLocal('groupChat.defaultReportName', {displayName: getDisplayNameForParticipant(participants[0], false)});
return Localize.translateLocal('groupChat.defaultReportName', {displayName: getDisplayNameForParticipant(participantAccountIDs[0], false)});
}

function getParticipants(reportID: string) {
Expand Down
6 changes: 2 additions & 4 deletions src/pages/GroupChatNameEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPagePr
const {translate} = useLocalize();
const {inputCallbackRef} = useAutoFocusInput();

// We will try to get the chatName from the report or draft depending on what flow we are in
const draftParticipantAccountIDs = useMemo(() => (groupChatDraft?.participants ?? []).map((participant) => participant.accountID), [groupChatDraft?.participants]);
const existingReportName = useMemo(
() => (report ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getGroupChatName(draftParticipantAccountIDs)),
[draftParticipantAccountIDs, report],
() => (report ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getGroupChatName(groupChatDraft?.participants)),
[groupChatDraft?.participants, report],
);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName;
Expand Down
3 changes: 1 addition & 2 deletions src/pages/NewChatConfirmPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
const {translate} = useLocalize();
const styles = useThemeStyles();
const personalData = useCurrentUserPersonalDetails();
const participantAccountIDs = (newGroupDraft?.participants ?? []).map((participant) => participant.accountID);
const selectedOptions = useMemo((): Participant[] => {
if (!newGroupDraft?.participants) {
return [];
Expand All @@ -61,7 +60,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
return options;
}, [allPersonalDetails, newGroupDraft?.participants]);

const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : ReportUtils.getGroupChatName(participantAccountIDs ?? []);
const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : ReportUtils.getGroupChatName(newGroupDraft?.participants);
const sections: ListItem[] = useMemo(
() =>
selectedOptions
Expand Down
Loading