Skip to content

Commit 5f45065

Browse files
Merge pull request Expensify#65888 from daledah/fix/65314
fix: unify invite message text
2 parents 5f9028b + 8f717f2 commit 5f45065

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/libs/OptionsListUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
getReportActionHtml,
7878
getReportActionMessageText,
7979
getRetractedMessage,
80+
getRoomChangeLogMessage,
8081
getSortedReportActions,
8182
getTravelUpdateMessage,
8283
getUpdateRoomDescriptionMessage,
@@ -88,6 +89,7 @@ import {
8889
isCreatedTaskReportAction,
8990
isDeletedAction,
9091
isDeletedParentAction,
92+
isInviteOrRemovedAction,
9193
isMarkAsClosedAction,
9294
isModifiedExpenseAction,
9395
isMoneyRequestAction,
@@ -831,6 +833,8 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
831833
lastMessageTextFromReport = getPolicyChangeMessage(lastReportAction);
832834
} else if (isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.TRAVEL_UPDATE)) {
833835
lastMessageTextFromReport = getTravelUpdateMessage(lastReportAction);
836+
} else if (isInviteOrRemovedAction(lastReportAction)) {
837+
lastMessageTextFromReport = getRoomChangeLogMessage(lastReportAction);
834838
} else if (isRenamedAction(lastReportAction)) {
835839
lastMessageTextFromReport = getRenamedAction(lastReportAction, isExpenseReport(report));
836840
} else if (isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION)) {

src/libs/ReportActionsUtils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,20 @@ function getCardIssuedMessage({
29072907
}
29082908
}
29092909

2910+
function getRoomChangeLogMessage(reportAction: ReportAction) {
2911+
if (!isInviteOrRemovedAction(reportAction)) {
2912+
return '';
2913+
}
2914+
const originalMessage = getOriginalMessage(reportAction);
2915+
const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? [];
2916+
const actionText =
2917+
isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM) || isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM)
2918+
? translateLocal('workspace.invite.invited')
2919+
: translateLocal('workspace.invite.removed');
2920+
const userText = (targetAccountIDs.length === 1 ? translateLocal('common.member') : translateLocal('common.members')).toLowerCase();
2921+
return `${actionText} ${targetAccountIDs.length} ${userText}`;
2922+
}
2923+
29102924
function getReportActions(report: Report) {
29112925
return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`];
29122926
}
@@ -3144,6 +3158,7 @@ export {
31443158
getWorkspaceCustomUnitRateUpdatedMessage,
31453159
getTagListNameUpdatedMessage,
31463160
getWorkspaceCustomUnitUpdatedMessage,
3161+
getRoomChangeLogMessage,
31473162
getReportActions,
31483163
getReopenedMessage,
31493164
getLeaveRoomMessage,

src/libs/SidebarUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ function getOptionData({
791791
? translateLocal('workspace.invite.invited')
792792
: translateLocal('workspace.invite.removed');
793793
const users = translateLocal(targetAccountIDsLength > 1 ? 'common.members' : 'common.member')?.toLocaleLowerCase();
794-
result.alternateText = formatReportLastMessageText(`${actorDisplayName ?? lastActorDisplayName} ${verb} ${targetAccountIDsLength} ${users}`);
794+
result.alternateText = formatReportLastMessageText(`${actorDisplayName ?? lastActorDisplayName}: ${verb} ${targetAccountIDsLength} ${users}`);
795795
const roomName = getReportName(allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${lastActionOriginalMessage?.reportID}`]) || lastActionOriginalMessage?.roomName;
796796
if (roomName) {
797797
const preposition =

tests/unit/SidebarUtilsTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ describe('SidebarUtils', () => {
12511251
});
12521252

12531253
// Then the alternate text should be equal to the message of the last action prepended with the last actor display name.
1254-
expect(result?.alternateText).toBe(`You invited 1 member`);
1254+
expect(result?.alternateText).toBe(`You: invited 1 member`);
12551255
});
12561256
it('returns the last action message as an alternate text if the action is MOVED type', async () => {
12571257
const report: Report = {

0 commit comments

Comments
 (0)