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

Start showing the beginningOfChatHistory in other room types #44667

Merged
merged 20 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
20 changes: 10 additions & 10 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP
const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report);
const isMultipleParticipant = participantAccountIDs.length > 1;
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant);
const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(report);
const welcomeMessage = ReportUtils.getWelcomeMessage(report);
const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, policy, participantAccountIDs);
const additionalText = moneyRequestOptions
.filter((item): item is Exclude<IOUType, typeof CONST.IOU.TYPE.REQUEST | typeof CONST.IOU.TYPE.SEND | typeof CONST.IOU.TYPE.INVOICE> => item !== CONST.IOU.TYPE.INVOICE)
Expand Down Expand Up @@ -101,11 +101,11 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP
</PressableWithoutFeedback>
) : (
<Text>
<Text>{translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne')}</Text>
<Text>{welcomeMessage.phrase1}</Text>
<Text style={[styles.textStrong]}>{ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)}</Text>
<Text>{translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo')}</Text>
<Text>{welcomeMessage.phrase2}</Text>
<Text style={[styles.textStrong]}>{ReportUtils.getPolicyName(report)}</Text>
<Text>{translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree')}</Text>
<Text>{welcomeMessage.phrase3}</Text>
</Text>
))}
{isChatRoom &&
Expand All @@ -125,8 +125,8 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP
</PressableWithoutFeedback>
) : (
<Text>
<Text>{roomWelcomeMessage.phrase1}</Text>
{roomWelcomeMessage.showReportName && (
<Text>{welcomeMessage.phrase1}</Text>
{welcomeMessage.showReportName && (
<Text
style={[styles.textStrong]}
onPress={navigateToReport}
Expand All @@ -135,22 +135,22 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP
{ReportUtils.getReportName(report)}
</Text>
)}
{roomWelcomeMessage.phrase2 !== undefined && <Text>{roomWelcomeMessage.phrase2}</Text>}
{welcomeMessage.phrase2 !== undefined && <Text>{welcomeMessage.phrase2}</Text>}
</Text>
))}
{isSelfDM && (
<Text>
<Text>{translate('reportActionsView.beginningOfChatHistorySelfDM')}</Text>
<Text>{welcomeMessage.phrase1}</Text>
</Text>
)}
{isSystemChat && (
<Text>
<Text>{translate('reportActionsView.beginningOfChatHistorySystemDM')}</Text>
<Text>{welcomeMessage.phrase1}</Text>
</Text>
)}
{isDefault && (
<Text>
<Text>{translate('reportActionsView.beginningOfChatHistory')}</Text>
<Text>{welcomeMessage.phrase1}</Text>
{displayNamesWithTooltips.map(({displayName, accountID}, index) => (
// eslint-disable-next-line react/no-array-index-key
<Text key={`${displayName}${index}`}>
Expand Down
30 changes: 29 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import * as UserUtils from './UserUtils';

type AvatarRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18;

type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string};
type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string; phrase3?: string};

type SpendBreakdown = {
nonReimbursableSpend: number;
Expand Down Expand Up @@ -1609,6 +1609,33 @@ function getRoomWelcomeMessage(report: OnyxEntry<Report>): WelcomeMessage {
return welcomeMessage;
}

function getWelcomeMessage(report: OnyxEntry<Report>): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {showReportName: true};
if (isChatRoom(report)) {
return getRoomWelcomeMessage(report);
}

if (isPolicyExpenseChat(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne');
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo');
welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree');
return welcomeMessage;
}

if (isSelfDM(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySelfDM');
return welcomeMessage;
}

if (isSystemChat(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySystemDM');
return welcomeMessage;
}

welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory');
return welcomeMessage;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns true if Concierge is one of the chat participants (1:1 as well as group chats)
*/
Expand Down Expand Up @@ -7151,6 +7178,7 @@ export {
getPolicyExpenseChat,
getPolicyName,
getPolicyType,
getWelcomeMessage,
getReimbursementDeQueuedActionMessage,
getReimbursementQueuedActionMessage,
getReportActionActorAccountID,
Expand Down
66 changes: 65 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ import {hasValidDraftComment} from './DraftCommentUtils';
import localeCompare from './LocaleCompare';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
import {parseHtmlToText} from './OnyxAwareParser';
import * as OptionsListUtils from './OptionsListUtils';
import * as PolicyUtils from './PolicyUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportUtils from './ReportUtils';
import * as TaskUtils from './TaskUtils';

const visibleReportActionItems: ReportActions = {};
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
},
});
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
Expand Down Expand Up @@ -381,7 +389,7 @@ function getOptionData({
} else {
result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : ReportActionsUtils.getLastVisibleMessage(report.reportID, {}, lastAction)?.lastMessageText;
if (!result.alternateText) {
result.alternateText = Localize.translate(preferredLocale, 'report.noActivityYet');
result.alternateText = ReportUtils.formatReportLastMessageText(getReportBeginningOfChatHistoryMessage(report) ?? '');
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
Expand Down Expand Up @@ -447,8 +455,64 @@ function getOptionData({

return result;
}
function getReportBeginningOfChatHistoryMessage(report: OnyxEntry<Report>): string | undefined {
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
const welcomeMessage = ReportUtils.getWelcomeMessage(report);
if (ReportUtils.isPolicyExpenseChat(report)) {
if (report?.description) {
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
return parseHtmlToText(report.description);
}
return `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(report)} ${
welcomeMessage.phrase3
}`;
}

if (ReportUtils.isChatRoom(report)) {
if (report?.description) {
return parseHtmlToText(report.description);
}
return `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`;
}

if (ReportUtils.isSelfDM(report) || ReportUtils.isSystemChat(report)) {
return `${welcomeMessage.phrase1}`;
}
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
const isChatRoom = ReportUtils.isChatRoom(report);
const isSelfDM = ReportUtils.isSelfDM(report);
const isInvoiceRoom = ReportUtils.isInvoiceRoom(report);
const isSystemChat = ReportUtils.isSystemChat(report);
const isDefault = !(isChatRoom || isPolicyExpenseChat || isSelfDM || isInvoiceRoom || isSystemChat);

if (isDefault) {
const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report);
const isMultipleParticipant = participantAccountIDs.length > 1;
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(
OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails),
isMultipleParticipant,
);
const displayNamesWithTooltipsText = displayNamesWithTooltips
.map(({displayName, pronouns}, index) => {
const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`;

if (index === displayNamesWithTooltips.length - 1) {
return `${formattedText}.`;
}
if (index === displayNamesWithTooltips.length - 2) {
return `${formattedText} ${Localize.translateLocal('common.and')}`;
}
if (index < displayNamesWithTooltips.length - 2) {
return `${formattedText},`;
}

return '';
})
.join(' ');
return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`;
}
}

export default {
getOptionData,
getOrderedReportIDs,
getReportBeginningOfChatHistoryMessage,
};
Loading