Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 13 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,18 @@ function getOptionData({
const actionMessage = getReportActionMessageText(lastAction);
result.alternateText = actionMessage ? `${lastActorDisplayName}: ${actionMessage}` : '';
} else if (isInviteOrRemovedAction(lastAction)) {
let actorDetails;
if (lastAction.actorAccountID) {
actorDetails = personalDetails?.[lastAction?.actorAccountID];
}
let actorDisplayName = lastAction?.person?.[0]?.text;
if (!actorDetails && actorDisplayName && lastAction.actorAccountID) {
actorDetails = {
displayName: actorDisplayName,
accountID: lastAction.actorAccountID,
};
}
actorDisplayName = actorDetails ? getLastActorDisplayName(actorDetails, hasMultipleParticipants) : undefined;
const lastActionOriginalMessage = lastAction?.actionName ? getOriginalMessage(lastAction) : null;
const targetAccountIDs = lastActionOriginalMessage?.targetAccountIDs ?? [];
const targetAccountIDsLength = targetAccountIDs.length !== 0 ? targetAccountIDs.length : report.lastMessageHtml?.match(/<mention-user[^>]*><\/mention-user>/g)?.length ?? 0;
Expand All @@ -548,7 +560,7 @@ function getOptionData({
? translate(preferredLocale, 'workspace.invite.invited')
: translate(preferredLocale, 'workspace.invite.removed');
const users = translate(preferredLocale, targetAccountIDsLength > 1 ? 'workspace.invite.users' : 'workspace.invite.user');
result.alternateText = formatReportLastMessageText(`${lastActorDisplayName} ${verb} ${targetAccountIDsLength} ${users}`);
result.alternateText = formatReportLastMessageText(`${actorDisplayName ?? lastActorDisplayName} ${verb} ${targetAccountIDsLength} ${users}`);
const roomName = getReportName(allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${lastActionOriginalMessage?.reportID}`]);
if (roomName) {
const preposition =
Expand Down
67 changes: 67 additions & 0 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,73 @@ describe('SidebarUtils', () => {

expect(optionData?.alternateText).toBe(`${policy.name} ${CONST.DOT_SEPARATOR} test message`);
});
it('returns the last action message as an alternate text if the action is INVITETOROOM type', async () => {
// When a report has last action of INVITETOROOM type
const policy: Policy = {
...createRandomPolicy(1),
role: CONST.POLICY.ROLE.ADMIN,
pendingAction: null,
};
const session = {
authToken: 'sensitive-auth-token',
encryptedAuthToken: 'sensitive-encrypted-token',
email: 'user@example.com',
accountID: 12345,
};
const report: Report = {
...createRandomReport(4),
chatType: 'policyRoom',
lastMessageHtml: 'invited 1 user',
lastMessageText: 'invited 1 user',
lastVisibleActionCreated: '2025-01-20 12:30:03.784',
participants: {
'12345': {
notificationPreference: 'daily',
role: 'admin',
},
},
policyID: '1',
};
const lastAction: ReportAction = {
...createRandomReportAction(2),
message: [
{
type: 'COMMENT',
html: '<muted-text>invited <mention-user accountID=19268914></mention-user></muted-text>',
text: 'invited',
isEdited: false,
whisperedTo: [],
isDeletedParentAction: false,
deleted: '',
},
],
originalMessage: {
lastModified: '2025-03-04 10:32:10.416',
targetAccountIDs: [19268914],
},
actorAccountID: 12345,
actionName: CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM,
};
const reportActions: ReportActions = {[lastAction.reportActionID]: lastAction};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, reportActions);
await Onyx.set(ONYXKEYS.SESSION, session);
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}1`, policy);
const result = SidebarUtils.getOptionData({
report,
reportActions,
reportNameValuePairs: {},
hasViolations: false,
personalDetails: {},
policy: undefined,
parentReportAction: undefined,
preferredLocale: CONST.LOCALES.EN,
oneTransactionThreadReport: undefined,
});

// Then the alternate text should be equal to the message of the last action prepended with the last actor display name.
expect(result?.alternateText).toBe(`invited 1 user`);
});
});
});
});