Skip to content

Commit

Permalink
Merge pull request #34362 from narefyev91/fix-invited-members-in-admi…
Browse files Browse the repository at this point in the history
…n-rooms

Fix invited members for admin threads
  • Loading branch information
blimpich authored Jan 23, 2024
2 parents 7f58856 + a17a9fa commit f267baf
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
TransactionViolation,
} from '@src/types/onyx';
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type {IOUMessage, OriginalMessageActionName, OriginalMessageCreated} from '@src/types/onyx/OriginalMessage';
import type {ChangeLog, IOUMessage, OriginalMessageActionName, OriginalMessageCreated} from '@src/types/onyx/OriginalMessage';
import type {Status} from '@src/types/onyx/PersonalDetails';
import type {NotificationPreference} from '@src/types/onyx/Report';
import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction';
Expand Down Expand Up @@ -1616,8 +1616,7 @@ function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = f
// 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) {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (personalDetails.isOptimisticPersonalDetail === true && formattedLogin) {
return formattedLogin;
}

Expand Down Expand Up @@ -2318,6 +2317,48 @@ function getModifiedExpenseOriginalMessage(oldTransaction: OnyxEntry<Transaction
return originalMessage;
}

/**
* Check if original message is an object and can be used as a ChangeLog type
* @param originalMessage
*/
function isChangeLogObject(originalMessage?: ChangeLog): ChangeLog | undefined {
if (originalMessage && typeof originalMessage === 'object') {
return originalMessage;
}
return undefined;
}

/**
* Build invited usernames for admin chat threads
* @param parentReportAction
* @param parentReportActionMessage
*/
function getAdminRoomInvitedParticipants(parentReportAction: ReportAction | Record<string, never>, parentReportActionMessage: string) {
if (!parentReportAction?.originalMessage) {
return '';
}
const originalMessage = isChangeLogObject(parentReportAction.originalMessage);
const participantAccountIDs = originalMessage?.targetAccountIDs ?? [];

const participants = participantAccountIDs.map((id) => getDisplayNameForParticipant(id));
const users = participants.length > 1 ? participants.join(` ${Localize.translateLocal('common.and')} `) : participants[0];
if (!users) {
return parentReportActionMessage;
}
const actionType = parentReportAction.actionName;
const isInviteAction = actionType === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || actionType === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM;

const verbKey = isInviteAction ? 'workspace.invite.invited' : 'workspace.invite.removed';
const prepositionKey = isInviteAction ? 'workspace.invite.to' : 'workspace.invite.from';

const verb = Localize.translateLocal(verbKey);
const preposition = Localize.translateLocal(prepositionKey);

const roomName = originalMessage?.roomName ?? '';

return roomName ? `${verb} ${users} ${preposition} ${roomName}` : `${verb} ${users}`;
}

/**
* Get the title for a report.
*/
Expand All @@ -2340,6 +2381,9 @@ function getReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = nu
) {
return Localize.translateLocal('parentReportAction.hiddenMessage');
}
if (isAdminRoom(report) || isUserCreatedPolicyRoom(report)) {
return getAdminRoomInvitedParticipants(parentReportAction, parentReportActionMessage);
}
return parentReportActionMessage || Localize.translateLocal('parentReportAction.deletedMessage');
}

Expand Down

0 comments on commit f267baf

Please sign in to comment.