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

fixes : copy to clipboard mention whisper message and hide mention whisper on any action #34560

Merged
merged 19 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
24 changes: 23 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import OnyxUtils from 'react-native-onyx/lib/utils';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ActionName, ChangeLog, OriginalMessageReimbursementDequeued} from '@src/types/onyx/OriginalMessage';
import type {ActionName, ChangeLog, OriginalMessageActionableMentionWhisper, OriginalMessageReimbursementDequeued} from '@src/types/onyx/OriginalMessage';
import type Report from '@src/types/onyx/Report';
import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction';
import type ReportAction from '@src/types/onyx/ReportAction';
Expand Down Expand Up @@ -810,6 +810,26 @@ function hasRequestFromCurrentAccount(reportID: string, currentAccountID: number
return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID);
}

function isActionableMentionWhisper(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER;
}

function getActionableMentionWhisperMessage(reportAction: OnyxEntry<ReportAction>): string {
const originalMessage = reportAction?.originalMessage as OriginalMessageActionableMentionWhisper['originalMessage'];
const targetAccountIDs: number[] = originalMessage?.inviteeAccountIDs ?? [];
const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0);
const mentionElements = targetAccountIDs.map((accountID): string => {
const personalDetail = personalDetails.find((personal) => personal.accountID === accountID);
const handleText = PersonalDetailsUtils.getEffectiveDisplayName(personalDetail) ?? Localize.translateLocal('common.hidden');
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
return `<mention-user accountID=${accountID}>@${handleText}</mention-user>`;
});
const preMentionsText = 'Heads up, ';
const mentions = mentionElements.join(', ').replace(/, ([^,]*)$/, ' and $1');
const postMentionsText = ` ${mentionElements.length > 1 ? "aren't members" : "isn't a member"} of this room.`;
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved

return `${preMentionsText}${mentions}${postMentionsText}`;
}

export {
extractLinksFromMessageHtml,
getAllReportActions,
Expand Down Expand Up @@ -860,6 +880,8 @@ export {
getMemberChangeMessageFragment,
getMemberChangeMessagePlainText,
isReimbursementDeQueuedAction,
isActionableMentionWhisper,
getActionableMentionWhisperMessage,
};

export type {LastVisibleMessage};
3 changes: 3 additions & 0 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ const ContextMenuActions: ContextMenuAction[] = [
} else if (ReportActionsUtils.isSubmittedExpenseAction(reportAction)) {
const submittedMessage = reportAction?.message?.reduce((acc, curr) => `${acc}${curr.text}`, '');
Clipboard.setString(submittedMessage ?? '');
} else if (ReportActionsUtils.isActionableMentionWhisper(reportAction)) {
const mentionWhisperMessage = ReportActionsUtils.getActionableMentionWhisperMessage(reportAction);
setClipboardMessage(mentionWhisperMessage);
} else if (content) {
setClipboardMessage(content);
}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ function ReportActionItem(props) {
);

const actionableItemButtons = useMemo(() => {
if (!(props.action.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && !lodashGet(props.action, 'originalMessage.resolution', null))) {
if (!(ReportActionsUtils.isActionableMentionWhisper(props.action) && !lodashGet(props.action, 'originalMessage.resolution', null))) {
return [];
}
return [
Expand Down Expand Up @@ -687,6 +687,11 @@ function ReportActionItem(props) {
return null;
}

// if isActionableMentionWhisper, and resolved, then we don't want to render anything
if (ReportActionsUtils.isActionableMentionWhisper(props.action) && lodashGet(props.action, 'originalMessage.resolution', null)) {
return null;
}
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved

const hasErrors = !_.isEmpty(props.action.errors);
const whisperedToAccountIDs = props.action.whisperedToAccountIDs || [];
const isWhisper = whisperedToAccountIDs.length > 0;
Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,6 @@ export type {
OriginalMessageIOU,
OriginalMessageCreated,
OriginalMessageAddComment,
OriginalMessageActionableMentionWhisper,
OriginalMessageReimbursementDequeued,
};
Loading