Skip to content

Commit

Permalink
remove podfile
Browse files Browse the repository at this point in the history
  • Loading branch information
waterim committed Mar 26, 2024
1 parent c2f2ed9 commit fc683cb
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 100 deletions.
3 changes: 1 addition & 2 deletions src/components/LHNOptionsList/OptionRowLHN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import DateUtils from '@libs/DateUtils';
import DomUtils from '@libs/DomUtils';
import {getGroupChatName} from '@libs/GroupChatUtils';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -109,7 +108,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti

const isGroupChat = ReportUtils.isGroupChat(optionItem) || ReportUtils.isDeprecatedGroupDM(optionItem);

const fullTitle = isGroupChat ? getGroupChatName(report?.participantAccountIDs ?? []) : optionItem.text;
const fullTitle = isGroupChat ? ReportUtils.getGroupChatName(report?.participantAccountIDs ?? []) : optionItem.text;

const subscriptAvatarBorderColor = isFocused ? focusedBackgroundColor : theme.sidebar;
return (
Expand Down
24 changes: 0 additions & 24 deletions src/libs/GroupChatUtils.ts

This file was deleted.

120 changes: 67 additions & 53 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import * as CollectionUtils from './CollectionUtils';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import originalGetReportPolicyID from './getReportPolicyID';
// eslint-disable-next-line import/no-cycle
import * as GroupChatUtils from './GroupChatUtils';
import isReportMessageAttachment from './isReportMessageAttachment';
import localeCompare from './LocaleCompare';
import * as LocalePhoneNumber from './LocalePhoneNumber';
Expand Down Expand Up @@ -1612,6 +1610,71 @@ function getWorkspaceIcon(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> =
return workspaceIcon;
}

/**
* Gets the personal details for a login by looking in the ONYXKEYS.PERSONAL_DETAILS_LIST Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx,
* then a default object is constructed.
*/
function getPersonalDetailsForAccountID(accountID: number): Partial<PersonalDetails> {
if (!accountID) {
return {};
}
return (
allPersonalDetails?.[accountID] ?? {
avatar: UserUtils.getDefaultAvatar(accountID),
isOptimisticPersonalDetail: true,
}
);
}

/**
* Get the displayName for a single report participant.
*/
function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = false, shouldFallbackToHidden = true, shouldAddCurrentUserPostfix = false): string {
if (!accountID) {
return '';
}

const personalDetails = getPersonalDetailsForAccountID(accountID);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const formattedLogin = LocalePhoneNumber.formatPhoneNumber(personalDetails.login || '');
// This is to check if account is an invite/optimistically created one
// and prevent from falling back to 'Hidden', so a correct value is shown
// when searching for a new user
if (personalDetails.isOptimisticPersonalDetail === true) {
return formattedLogin;
}

// For selfDM, we display the user's displayName followed by '(you)' as a postfix
const shouldAddPostfix = shouldAddCurrentUserPostfix && accountID === currentUserAccountID;

const longName = PersonalDetailsUtils.getDisplayNameOrDefault(personalDetails, formattedLogin, shouldFallbackToHidden, shouldAddPostfix);

// If the user's personal details (first name) should be hidden, make sure we return "hidden" instead of the short name
if (shouldFallbackToHidden && longName === Localize.translateLocal('common.hidden')) {
return longName;
}

const shortName = personalDetails.firstName ? personalDetails.firstName : longName;
return shouldUseShortForm ? shortName : longName;
}

/**
* Returns the report name if the report is a group chat
*/
function getGroupChatName(participantAccountIDs: number[], shouldApplyLimit = false): string | undefined {
let participants = participantAccountIDs;
if (shouldApplyLimit) {
participants = participants.slice(0, 5);
}
const isMultipleParticipantReport = participants.length > 1;

return participants
.map((participant) => getDisplayNameForParticipant(participant, isMultipleParticipantReport))
.sort((first, second) => localeCompare(first ?? '', second ?? ''))
.filter(Boolean)
.join(', ');
}

/**
* Returns the appropriate icons for the given chat report using the stored personalDetails.
* The Avatar sources can be URLs or Icon components according to the chat type.
Expand Down Expand Up @@ -1737,62 +1800,14 @@ function getIcons(
source: getDefaultGroupAvatar(report.reportID),
id: -1,
type: CONST.ICON_TYPE_AVATAR,
name: GroupChatUtils.getGroupChatName(report.participantAccountIDs ?? []),
name: getGroupChatName(report.participantAccountIDs ?? []),
};
return [groupChatIcon];
}

return getIconsForParticipants(report?.participantAccountIDs ?? [], personalDetails);
}

/**
* Gets the personal details for a login by looking in the ONYXKEYS.PERSONAL_DETAILS_LIST Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx,
* then a default object is constructed.
*/
function getPersonalDetailsForAccountID(accountID: number): Partial<PersonalDetails> {
if (!accountID) {
return {};
}
return (
allPersonalDetails?.[accountID] ?? {
avatar: UserUtils.getDefaultAvatar(accountID),
isOptimisticPersonalDetail: true,
}
);
}

/**
* Get the displayName for a single report participant.
*/
function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = false, shouldFallbackToHidden = true, shouldAddCurrentUserPostfix = false): string {
if (!accountID) {
return '';
}

const personalDetails = getPersonalDetailsForAccountID(accountID);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const formattedLogin = LocalePhoneNumber.formatPhoneNumber(personalDetails.login || '');
// This is to check if account is an invite/optimistically created one
// and prevent from falling back to 'Hidden', so a correct value is shown
// when searching for a new user
if (personalDetails.isOptimisticPersonalDetail === true) {
return formattedLogin;
}

// For selfDM, we display the user's displayName followed by '(you)' as a postfix
const shouldAddPostfix = shouldAddCurrentUserPostfix && accountID === currentUserAccountID;

const longName = PersonalDetailsUtils.getDisplayNameOrDefault(personalDetails, formattedLogin, shouldFallbackToHidden, shouldAddPostfix);

// If the user's personal details (first name) should be hidden, make sure we return "hidden" instead of the short name
if (shouldFallbackToHidden && longName === Localize.translateLocal('common.hidden')) {
return longName;
}

const shortName = personalDetails.firstName ? personalDetails.firstName : longName;
return shouldUseShortForm ? shortName : longName;
}

function getDisplayNamesWithTooltips(
personalDetailsList: PersonalDetails[] | PersonalDetailsList | OptionData[],
isMultipleParticipantReport: boolean,
Expand Down Expand Up @@ -1860,8 +1875,6 @@ function getDeletedParentActionMessageForChatReport(reportAction: OnyxEntry<Repo

/**
* Returns the preview message for `REIMBURSEMENTQUEUED` action
*
*/
function getReimbursementQueuedActionMessage(reportAction: OnyxEntry<ReportAction>, report: OnyxEntry<Report>, shouldUseShortDisplayName = true): string {
const submitterDisplayName = getDisplayNameForParticipant(report?.ownerAccountID, shouldUseShortDisplayName) ?? '';
Expand Down Expand Up @@ -5786,6 +5799,7 @@ export {
isGroupChat,
isTrackExpenseReport,
hasActionsWithErrors,
getGroupChatName,
};

export type {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2288,8 +2288,9 @@ function createSplitsAndOnyxData(
let newChat: ReportUtils.OptimisticChatReport | EmptyObject = {};

if (!existingSplitChatReport && participants.length > 1) {
const allParticipantsAccountIDs = [...participantAccountIDs, currentUserAccountID];
newChat = ReportUtils.buildOptimisticChatReport(
participantAccountIDs,
allParticipantsAccountIDs,
'',
CONST.REPORT.CHAT_TYPE.GROUP,
undefined,
Expand Down
17 changes: 8 additions & 9 deletions src/pages/NewChatConfirmPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import * as GroupChatUtils from '@libs/GroupChatUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand All @@ -40,18 +39,18 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
const StyleUtils = useStyleUtils();
const styles = useThemeStyles();
const personalData = useCurrentUserPersonalDetails();
const participantAccountIDs = newGroupDraft?.participants.map((participant: {accountID: number}) => participant.accountID);
const participantAccountIDs = newGroupDraft?.participants.map((participant) => participant.accountID);
const selectedOptions = useMemo((): Participant[] => {
let options: Participant[] = [];
if (newGroupDraft?.participants) {
options = newGroupDraft?.participants.map((participant: {accountID: number; login: string}) =>
OptionsListUtils.getParticipantsOption({accountID: participant.accountID, login: participant.login, reportID: ''}, allPersonalDetails),
);
if (!newGroupDraft?.participants) {
return [];
}
const options: Participant[] = newGroupDraft?.participants.map((participant) =>
OptionsListUtils.getParticipantsOption({accountID: participant.accountID, login: participant.login, reportID: ''}, allPersonalDetails),
);
return options;
}, [allPersonalDetails, newGroupDraft?.participants]);

const groupName = GroupChatUtils.getGroupChatName(participantAccountIDs ?? []);
const groupName = ReportUtils.getGroupChatName(participantAccountIDs ?? []);

const sections: ListItem[] = useMemo(
() =>
Expand Down Expand Up @@ -101,7 +100,7 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
if (!newGroupDraft) {
return;
}
const logins: string[] = newGroupDraft.participants.map((participant: {login: string}) => participant.login);
const logins: string[] = newGroupDraft.participants.map((participant) => participant.login);
Report.navigateToAndOpenReport(logins, true, groupName);
};

Expand Down
8 changes: 5 additions & 3 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, isSearchingF
* Navigates to create group confirm page
*/
const navigateToConfirmPage = () => {
const selectedParticipants: SelectedParticipant[] = selectedOptions.map((option: OptionData) => ({login: option.login ?? '', accountID: option.accountID ?? -1}));
if (!personalData || !personalData.login || !personalData.accountID) {
return;
}
const selectedParticipants: SelectedParticipant[] = selectedOptions.map((option: OptionData) => ({login: option.login ?? '', accountID: option.accountID ?? -1}));
const logins = [...selectedParticipants, {login: personalData.login, accountID: personalData.accountID}];
Report.setGroupDraft(logins);
Navigation.navigate(ROUTES.NEW_CHAT_CONFIRM);
Expand All @@ -202,8 +202,8 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, isSearchingF
const updateOptions = useCallback(() => {
let newSelectedOptions;
if (newGroupDraft?.participants) {
const selectedParticipants = newGroupDraft?.participants.filter((participant: SelectedParticipant) => participant.accountID !== personalData.accountID);
newSelectedOptions = selectedParticipants.map((participant: SelectedParticipant): OptionData => {
const selectedParticipants = newGroupDraft.participants.filter((participant) => participant.accountID !== personalData.accountID);
newSelectedOptions = selectedParticipants.map((participant): OptionData => {
const baseOption = OptionsListUtils.getParticipantsOption({accountID: participant.accountID, login: participant.login, reportID: ''}, personalDetails);
return {...baseOption, reportID: baseOption.reportID ?? ''};
});
Expand Down Expand Up @@ -337,3 +337,5 @@ export default withOnyx<NewChatPageProps, NewChatPageWithOnyxProps>({
initWithStoredValues: false,
},
})(NewChatPage);

export type {SelectedParticipant};
3 changes: 1 addition & 2 deletions src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import {getGroupChatName} from '@libs/GroupChatUtils';
import * as HeaderUtils from '@libs/HeaderUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {ReportWithoutHasDraft} from '@libs/OnyxSelectors/reportWithoutHasDraftSelector';
Expand Down Expand Up @@ -90,7 +89,7 @@ function HeaderView({report, personalDetails, parentReport, parentReportAction,
const isTaskReport = ReportUtils.isTaskReport(report);
const reportHeaderData = !isTaskReport && !isChatThread && report.parentReportID ? parentReport : report;
// Use sorted display names for the title for group chats on native small screen widths
const title = isGroupChat ? getGroupChatName(report.participantAccountIDs ?? [], true) : ReportUtils.getReportName(reportHeaderData);
const title = isGroupChat ? ReportUtils.getGroupChatName(report.participantAccountIDs ?? [], true) : ReportUtils.getReportName(reportHeaderData);
const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData);
const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(reportHeaderData);
const isConcierge = ReportUtils.hasSingleParticipant(report) && participants.includes(CONST.ACCOUNT_ID.CONCIERGE);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/settings/Report/ReportSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {getGroupChatName} from '@libs/GroupChatUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import type {ReportSettingsNavigatorParamList} from '@navigation/types';
Expand Down Expand Up @@ -48,7 +47,8 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {

const shouldShowNotificationPref = !isMoneyRequestReport && report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
const roomNameLabel = translate(isMoneyRequestReport ? 'workspace.editor.nameInputLabel' : 'newRoomPage.roomName');
const reportName = ReportUtils.isDeprecatedGroupDM(report) || ReportUtils.isGroupChat(report) ? getGroupChatName(report.participantAccountIDs ?? []) : ReportUtils.getReportName(report);
const reportName =
ReportUtils.isDeprecatedGroupDM(report) || ReportUtils.isGroupChat(report) ? ReportUtils.getGroupChatName(report.participantAccountIDs ?? []) : ReportUtils.getReportName(report);

const shouldShowWriteCapability = !isMoneyRequestReport;

Expand Down
7 changes: 3 additions & 4 deletions src/types/onyx/NewGroupChatDraft.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type {SelectedParticipant} from '@pages/NewChatPage';

type NewGroupChatDraft = {
participants: Array<{
login: string;
accountID: number;
}>;
participants: SelectedParticipant[];
reportName: string;
};

Expand Down

0 comments on commit fc683cb

Please sign in to comment.