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 16 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
21 changes: 11 additions & 10 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
import SidebarUtils from '@libs/SidebarUtils';
import CONST from '@src/CONST';
import type {IOUType} from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -42,7 +43,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 = SidebarUtils.getWelcomeMessage(report, policy);
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
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 +102,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 +126,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 +136,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
35 changes: 1 addition & 34 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ 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 SpendBreakdown = {
nonReimbursableSpend: number;
reimbursableSpend: number;
Expand Down Expand Up @@ -1616,37 +1614,6 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry<ReportAction>, rep
return isActionOwner || isAdmin;
}

/**
* Get welcome message based on room type
*/
function getRoomWelcomeMessage(report: OnyxEntry<Report>): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {showReportName: true};
const workspaceName = getPolicyName(report);

if (isArchivedRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartOne');
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo');
} else if (isDomainRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartOne', {domainRoom: report?.reportName ?? ''});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartTwo');
} else if (isAdminRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartOne', {workspaceName});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartTwo');
} else if (isAnnounceRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartOne', {workspaceName});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartTwo', {workspaceName});
} else if (isInvoiceRoom(report)) {
welcomeMessage.showReportName = false;
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryInvoiceRoom');
} else {
// Message for user created rooms or other room types.
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne');
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo');
}

return welcomeMessage;
}

/**
* Returns true if Concierge is one of the chat participants (1:1 as well as group chats)
*/
Expand Down Expand Up @@ -7211,7 +7178,6 @@ export {
getReportPreviewMessage,
getReportRecipientAccountIDs,
getRoom,
getRoomWelcomeMessage,
getRootParentReport,
getRouteFromLink,
getSystemChat,
Expand Down Expand Up @@ -7284,6 +7250,7 @@ export {
isIOUReport,
isIOUReportUsingReport,
isJoinRequestInAdminRoom,
isDomainRoom,
isMoneyRequest,
isMoneyRequestReport,
isMoneyRequestReportPendingDeletion,
Expand Down
144 changes: 116 additions & 28 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ import localeCompare from './LocaleCompare';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
import * as OptionsListUtils from './OptionsListUtils';
import Parser from './Parser';
import * as PolicyUtils from './PolicyUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportUtils from './ReportUtils';
import * as TaskUtils from './TaskUtils';

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

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 @@ -386,38 +396,12 @@ 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(getWelcomeMessage(report, policy).messageText ?? Localize.translateLocal('report.noActivityYet'));
}
}
} else {
if (!lastMessageText) {
if (ReportUtils.isSystemChat(report)) {
lastMessageText = Localize.translate(preferredLocale, 'reportActionsView.beginningOfChatHistorySystemDM');
} else if (ReportUtils.isSelfDM(report)) {
lastMessageText = Localize.translate(preferredLocale, 'reportActionsView.beginningOfChatHistorySelfDM');
} else {
// Here we get the beginning of chat history message and append the display name for each user, adding pronouns if there are any.
// We also add a fullstop after the final name, the word "and" before the final name and commas between all previous names.
lastMessageText =
Localize.translate(preferredLocale, 'reportActionsView.beginningOfChatHistory') +
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.translate(preferredLocale, 'common.and')}`;
}
if (index < displayNamesWithTooltips.length - 2) {
return `${formattedText},`;
}

return '';
})
.join(' ');
}
lastMessageText = ReportUtils.formatReportLastMessageText(getWelcomeMessage(report, policy).messageText ?? Localize.translateLocal('report.noActivityYet'));
}

result.alternateText =
Expand Down Expand Up @@ -458,7 +442,111 @@ function getOptionData({
return result;
}

function getWelcomeMessage(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {showReportName: true};
if (ReportUtils.isChatThread(report) || ReportUtils.isTaskReport(report)) {
return welcomeMessage;
}
Comment on lines +482 to +484
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this logic coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For these cases, I think it doesn't make sense to display the message This is the beginning of your chat with in LHN for the chat thread or task report.


if (ReportUtils.isChatRoom(report)) {
return getRoomWelcomeMessage(report);
}

if (ReportUtils.isPolicyExpenseChat(report)) {
if (policy?.description) {
welcomeMessage.messageText = Parser.htmlToText(policy.description);
welcomeMessage.messageHtml = policy.description;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
} else {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne');
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo');
welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree');
welcomeMessage.messageText = `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #51409 {BZ checklist}, there was small regession, the translation keys have spacing at end already and we addeed spacing here also resulting in double spacing

report,
)} ${welcomeMessage.phrase3}`;
}
return welcomeMessage;
}

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

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

welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory');
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})`;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved

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(' ');
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved

welcomeMessage.messageText = `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`;
return welcomeMessage;
}

/**
* Get welcome message based on room type
*/
function getRoomWelcomeMessage(report: OnyxEntry<Report>): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {showReportName: true};
const workspaceName = ReportUtils.getPolicyName(report);

if (report?.description) {
welcomeMessage.messageText = Parser.htmlToText(report.description);
welcomeMessage.messageHtml = report.description;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
return welcomeMessage;
}
if (ReportUtils.isArchivedRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartOne');
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo');
} else if (ReportUtils.isDomainRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartOne', {domainRoom: report?.reportName ?? ''});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartTwo');
} else if (ReportUtils.isAdminRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartOne', {workspaceName});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartTwo');
} else if (ReportUtils.isAnnounceRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartOne', {workspaceName});
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartTwo', {workspaceName});
} else if (ReportUtils.isInvoiceRoom(report)) {
welcomeMessage.showReportName = false;
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryInvoiceRoom');
} else {
// Message for user created rooms or other room types.
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne');
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo');
}
welcomeMessage.messageText = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`;

return welcomeMessage;
}

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