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

Fix "New message" button shows when resolving an actionable mention whisper #50247

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
3 changes: 1 addition & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ Onyx.connect({
ReportActionUtils.shouldReportActionBeVisible(reportAction, actionKey) &&
!ReportActionUtils.isWhisperAction(reportAction) &&
reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED &&
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
!ReportActionUtils.isResolvedActionTrackExpense(reportAction),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
);
const reportActionForDisplay = reportActionsForDisplay.at(0);
if (!reportActionForDisplay) {
Expand Down
77 changes: 40 additions & 37 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,39 @@ function isReportActionDeprecated(reportAction: OnyxEntry<ReportAction>, key: st
return false;
}

/**
* Checks if a given report action corresponds to an actionable mention whisper.
* @param reportAction
*/
function isActionableMentionWhisper(reportAction: OnyxEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER);
}

/**
* Checks if a given report action corresponds to an actionable report mention whisper.
* @param reportAction
*/
function isActionableReportMentionWhisper(reportAction: OnyxEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_REPORT_MENTION_WHISPER> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_REPORT_MENTION_WHISPER);
}

/**
* Checks whether an action is actionable track expense.
*/
function isActionableTrackExpense(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER);
}

function isActionableWhisper(
reportAction: OnyxEntry<ReportAction>,
): reportAction is ReportAction<
| typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER
| typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER
| typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_REPORT_MENTION_WHISPER
> {
return isActionableMentionWhisper(reportAction) || isActionableTrackExpense(reportAction) || isActionableReportMentionWhisper(reportAction);
}

const {POLICY_CHANGE_LOG: policyChangelogTypes, ROOM_CHANGE_LOG: roomChangeLogTypes, ...otherActionTypes} = CONST.REPORT.ACTIONS.TYPE;
const supportedActionTypes: ReportActionName[] = [...Object.values(otherActionTypes), ...Object.values(policyChangelogTypes), ...Object.values(roomChangeLogTypes)];

Expand Down Expand Up @@ -662,6 +695,11 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key:
return true;
}

// If action is actionable whisper and resolved by user, then we don't want to render anything
if (isActionableWhisper(reportAction) && getOriginalMessage(reportAction)?.resolution) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line caused a regression. See #55855 for details.

return false;
}

// All other actions are displayed except thread parents, deleted, or non-pending actions
const isDeleted = isDeletedAction(reportAction);
const isPending = !!reportAction.pendingAction;
Expand All @@ -679,24 +717,6 @@ function shouldHideNewMarker(reportAction: OnyxEntry<ReportAction>): boolean {
return !isNetworkOffline && reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

/**
* Checks whether an action is actionable track expense.
*
*/
function isActionableTrackExpense(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER);
}

/**
* Checks whether an action is actionable track expense and resolved.
*
*/
function isResolvedActionTrackExpense(reportAction: OnyxEntry<ReportAction>): boolean {
const originalMessage = getOriginalMessage(reportAction);
const resolution = originalMessage && typeof originalMessage === 'object' && 'resolution' in originalMessage ? originalMessage?.resolution : null;
return isActionableTrackExpense(reportAction) && !!resolution;
}

/**
* Checks if a reportAction is fit for display as report last action, meaning that
* it satisfies shouldReportActionBeVisible, it's not whisper action and not deleted.
Expand All @@ -715,8 +735,7 @@ function shouldReportActionBeVisibleAsLastAction(reportAction: OnyxInputOrEntry<
return (
shouldReportActionBeVisible(reportAction, reportAction.reportActionID) &&
!(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction) && !isMoneyRequestAction(reportAction)) &&
!(isDeletedAction(reportAction) && !isDeletedParentAction(reportAction)) &&
!isResolvedActionTrackExpense(reportAction)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove checking isResolvedActionTrackExpense because shouldReportActionBeVisible already covers it with the new condition.

!(isDeletedAction(reportAction) && !isDeletedParentAction(reportAction))
);
}

Expand Down Expand Up @@ -1396,22 +1415,6 @@ 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>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER);
}

/**
* Checks if a given report action corresponds to an actionable report mention whisper.
* @param reportAction
*/
function isActionableReportMentionWhisper(reportAction: OnyxEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_REPORT_MENTION_WHISPER> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_REPORT_MENTION_WHISPER);
}

/**
* Constructs a message for an actionable mention whisper report action.
* @param reportAction
Expand Down Expand Up @@ -1802,6 +1805,7 @@ export {
getWhisperedTo,
hasRequestFromCurrentAccount,
isActionOfType,
isActionableWhisper,
isActionableJoinRequest,
isActionableJoinRequestPending,
isActionableMentionWhisper,
Expand Down Expand Up @@ -1834,7 +1838,6 @@ export {
isReportActionAttachment,
isReportActionDeprecated,
isReportPreviewAction,
isResolvedActionTrackExpense,
isReversedTransaction,
isRoomChangeLogAction,
isSentMoneyReportAction,
Expand Down
25 changes: 1 addition & 24 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import UnreadActionIndicator from '@components/UnreadActionIndicator';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useReportScrollManager from '@hooks/useReportScrollManager';

Check failure on line 37 in src/pages/home/report/ReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'useReportScrollManager' is defined but never used
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -200,20 +200,14 @@
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || -1}`);
const isReportActionLinked = linkedReportActionID && action.reportActionID && linkedReportActionID === action.reportActionID;
const reportScrollManager = useReportScrollManager();
const isActionableWhisper =
ReportActionsUtils.isActionableMentionWhisper(action) || ReportActionsUtils.isActionableTrackExpense(action) || ReportActionsUtils.isActionableReportMentionWhisper(action);
const originalMessage = ReportActionsUtils.getOriginalMessage(action);
const isActionableWhisper = ReportActionsUtils.isActionableWhisper(action);

const highlightedBackgroundColorIfNeeded = useMemo(
() => (isReportActionLinked ? StyleUtils.getBackgroundColorStyle(theme.messageHighlightBG) : {}),
[StyleUtils, isReportActionLinked, theme.messageHighlightBG],
);

const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(action);
const isOriginalMessageAnObject = originalMessage && typeof originalMessage === 'object';
const hasResolutionInOriginalMessage = isOriginalMessageAnObject && 'resolution' in originalMessage;
const prevActionResolution = usePrevious(isActionableWhisper && hasResolutionInOriginalMessage ? originalMessage?.resolution : null);

// IOUDetails only exists when we are sending money
const isSendingMoney =
Expand Down Expand Up @@ -360,18 +354,6 @@
[draftMessage, action, reportID, toggleContextMenuFromActiveReportAction, originalReportID, shouldDisplayContextMenu, disabledActions, isArchivedRoom, isChronosReport],
);

// Handles manual scrolling to the bottom of the chat when the last message is an actionable whisper and it's resolved.
// This fixes an issue where InvertedFlatList fails to auto scroll down and results in an empty space at the bottom of the chat in IOS.
useEffect(() => {
if (index !== 0 || !isActionableWhisper) {
return;
}

if (prevActionResolution !== (hasResolutionInOriginalMessage ? originalMessage.resolution : null)) {
reportScrollManager.scrollToIndex(index);
}
}, [index, originalMessage, prevActionResolution, reportScrollManager, isActionableWhisper, hasResolutionInOriginalMessage]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this workaround because the issue doesn't happen anymore after we exclude the resolved actionable whisper from the list.

const toggleReaction = useCallback(
(emoji: Emoji, ignoreSkinToneOnCompare?: boolean) => {
Report.toggleEmojiReaction(reportID, action, emoji, emojiReactions, undefined, ignoreSkinToneOnCompare);
Expand Down Expand Up @@ -879,11 +861,6 @@
return null;
}

// If action is actionable whisper and resolved by user, then we don't want to render anything
if (isActionableWhisper && (hasResolutionInOriginalMessage ? originalMessage.resolution : null)) {
return null;
}

// We currently send whispers to all report participants and hide them in the UI for users that shouldn't see them.
// This is a temporary solution needed for comment-linking.
// The long term solution will leverage end-to-end encryption and only targeted users will be able to decrypt.
Expand Down
Loading