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 deleting parent thread message temporary disappearing #26548

Merged
merged 9 commits into from
Sep 11, 2023
11 changes: 8 additions & 3 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ function isWhisperAction(action) {
}

/**
*
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
* Returns whether the comment is a thread parent message/the first message in a thread
*
* @param {Object} reportAction
* @param {String} reportID
* @returns {Boolean}
*/
function hasCommentThread(reportAction) {
return lodashGet(reportAction, 'childType', '') === CONST.REPORT.TYPE.CHAT && lodashGet(reportAction, 'childVisibleActionCount', 0) > 0;
function isThreadParentMessage(reportAction, reportID) {
const {childType, childVisibleActionCount = 0, childReportID} = reportAction;
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
return childType === CONST.REPORT.TYPE.CHAT && (childVisibleActionCount > 0 || String(childReportID) === reportID);
}

/**
Expand Down Expand Up @@ -628,7 +633,7 @@ export {
getLastClosedReportAction,
getLatestReportActionFromOnyxData,
isMoneyRequestAction,
hasCommentThread,
isThreadParentMessage,
getLinkedTransactionID,
getMostRecentReportActionLastModified,
getReportPreviewAction,
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
onyxData.optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`,
value: {[parentReportActionID]: {childReportID: reportID}},
value: {[parentReportActionID]: {childReportID: reportID, childType: CONST.REPORT.TYPE.CHAT}},
});
onyxData.failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${newReportObject.parentReportID}`,
value: {[parentReportActionID]: {childReportID: '0'}},
value: {[parentReportActionID]: {childReportID: '0', childType: ''}},
});
}
}
Expand Down Expand Up @@ -926,7 +926,7 @@ function deleteReportComment(reportID, reportAction) {
html: '',
text: '',
isEdited: true,
isDeletedParentAction: ReportActionsUtils.hasCommentThread(reportAction),
isDeletedParentAction: ReportActionsUtils.isThreadParentMessage(reportAction, reportID),
},
];
const optimisticReportActions = {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function ReportActionItem(props) {
{!props.draftMessage ? (
<View style={props.displayAsGroup && hasBeenFlagged ? styles.blockquote : {}}>
<ReportActionItemMessage
reportID={props.report.reportID}
action={props.action}
displayAsGroup={props.displayAsGroup}
isHidden={isHidden}
Expand Down Expand Up @@ -576,7 +577,7 @@ function ReportActionItem(props) {
<OfflineWithFeedback
onClose={() => ReportActions.clearReportActionErrors(props.report.reportID, props.action)}
pendingAction={props.draftMessage ? null : props.action.pendingAction}
shouldHideOnDelete={!ReportActionsUtils.hasCommentThread(props.action)}
shouldHideOnDelete={!ReportActionsUtils.isThreadParentMessage(props.action, props.report.reportID)}
errors={props.action.errors}
errorRowStyles={[styles.ml10, styles.mr2]}
needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(props.action)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function ReportActionItemFragment(props) {
// While offline we display the previous message with a strikethrough style. Once online we want to
// immediately display "[Deleted message]" while the delete action is pending.

if ((!props.network.isOffline && props.hasCommentThread && props.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) || props.fragment.isDeletedParentAction) {
if ((!props.network.isOffline && props.isThreadParentMessage && props.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) || props.fragment.isDeletedParentAction) {
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
return <RenderHTML html={`<comment>${props.translate('parentReportAction.deletedMessage')}</comment>`} />;
}

Expand Down
5 changes: 4 additions & 1 deletion src/pages/home/report/ReportActionItemMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const propTypes = {
/** Whether or not the message is hidden by moderation */
isHidden: PropTypes.bool,

/** The ID of the report */
reportID: PropTypes.string.isRequired,

/** localization props */
...withLocalizePropTypes,
};
Expand Down Expand Up @@ -53,7 +56,7 @@ function ReportActionItemMessage(props) {
fragment={fragment}
isAttachment={props.action.isAttachment}
iouMessage={iouMessage}
hasCommentThread={ReportActionsUtils.hasCommentThread(props.action)}
isThreadParentMessage={ReportActionsUtils.isThreadParentMessage(props.action, props.reportID)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add this prop reportID to the propTypes definition.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @Nodebrute , props.reportID is not defined in the propTypes , it should be added to this block

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've just fixed this one as well. I apologize for the numerous mistakes.

attachmentInfo={props.action.attachmentInfo}
pendingAction={props.action.pendingAction}
source={lodashGet(props.action, 'originalMessage.source')}
Expand Down
Loading