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 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function ActionableItemButtons(props: ActionableItemButtonsProps) {
const {translate} = useLocalize();

return (
<View style={[styles.flexRow, styles.gap4]}>
<View style={[styles.flexRow, styles.gap2]}>
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
{props.items?.map((item) => (
<Button
key={item.key}
Expand Down
33 changes: 32 additions & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Onyx from 'react-native-onyx';
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 @@ -800,6 +800,35 @@ function hasRequestFromCurrentAccount(reportID: string, currentAccountID: number
return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID);
}

/**
* Checks if a given report action corresponds to an actionable mention whisper.
* @param reportAction
*/
function isActionableMentionWhisper(reportAction: OnyxEntry<ReportAction>): boolean {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER;
}

/**
* Constructs a message for an actionable mention whisper report action.
* @param reportAction
* @returns the actionable mention whisper message.
*/
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}`;
}

/**
* @private
*/
Expand Down Expand Up @@ -875,6 +904,8 @@ export {
getMemberChangeMessageFragment,
getMemberChangeMessagePlainText,
isReimbursementDeQueuedAction,
isActionableMentionWhisper,
getActionableMentionWhisperMessage,
isCurrentActionUnread,
};

Expand Down
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 @@ -362,6 +362,9 @@ const ContextMenuActions: ContextMenuAction[] = [
} else if (ReportActionsUtils.isMemberChangeAction(reportAction)) {
const logMessage = ReportActionsUtils.getMemberChangeMessageFragment(reportAction).html ?? '';
setClipboardMessage(logMessage);
} else if (ReportActionsUtils.isActionableMentionWhisper(reportAction)) {
const mentionWhisperMessage = ReportActionsUtils.getActionableMentionWhisperMessage(reportAction);
setClipboardMessage(mentionWhisperMessage);
} else if (content) {
setClipboardMessage(content);
} else if (messageText) {
Expand Down
23 changes: 21 additions & 2 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import UnreadActionIndicator from '@components/UnreadActionIndicator';
import withLocalize from '@components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import usePrevious from '@hooks/usePrevious';
import useReportScrollManager from '@hooks/useReportScrollManager';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -156,12 +157,15 @@ function ReportActionItem(props) {
const originalReport = props.report.reportID === originalReportID ? props.report : ReportUtils.getReport(originalReportID);
const isReportActionLinked = props.linkedReportActionID && props.action.reportActionID && props.linkedReportActionID === props.action.reportActionID;

const reportScrollManager = useReportScrollManager();

const highlightedBackgroundColorIfNeeded = useMemo(
() => (isReportActionLinked ? StyleUtils.getBackgroundColorStyle(theme.hoverComponentBG) : {}),
[StyleUtils, isReportActionLinked, theme.hoverComponentBG],
);
const originalMessage = lodashGet(props.action, 'originalMessage', {});
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(props.action);
const prevActionResolution = usePrevious(lodashGet(props.action, 'originalMessage.resolution', null));

// IOUDetails only exists when we are sending money
const isSendingMoney = originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && _.has(originalMessage, 'IOUDetails');
Expand Down Expand Up @@ -293,6 +297,16 @@ function ReportActionItem(props) {
[props.draftMessage, props.action, props.report.reportID, toggleContextMenuFromActiveReportAction, originalReport, originalReportID],
);

useEffect(() => {
if (props.index !== 0 || !ReportActionsUtils.isActionableMentionWhisper(props.action)) {
return;
}

if (prevActionResolution !== lodashGet(props.action, 'originalMessage.resolution', null)) {
reportScrollManager.scrollToIndex(props.index);
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
}
}, [props.index, props.action, prevActionResolution, reportScrollManager]);

const toggleReaction = useCallback(
(emoji) => {
Report.toggleEmojiReaction(props.report.reportID, props.action, emoji, props.emojiReactions);
Expand All @@ -311,7 +325,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 All @@ -327,7 +341,7 @@ function ReportActionItem(props) {
onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING),
},
];
}, [props.action, props.report]);
}, [props.action, props.report.reportID]);

/**
* Get the content of ReportActionItem
Expand Down Expand Up @@ -698,6 +712,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 @@ -285,6 +285,7 @@ export type {
OriginalMessageCreated,
OriginalMessageRenamed,
OriginalMessageAddComment,
OriginalMessageActionableMentionWhisper,
OriginalMessageChronosOOOList,
OriginalMessageSource,
OriginalMessageReimbursementDequeued,
Expand Down
Loading