Skip to content

Commit

Permalink
Merge pull request #26548 from Nodebrute/threadHeader
Browse files Browse the repository at this point in the history
Fix deleting parent thread message temporary disappearing
  • Loading branch information
Beamanator authored Sep 11, 2023
2 parents 23933fd + 326010b commit 4abaeba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ function isWhisperAction(action) {
}

/**
* 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;
return childType === CONST.REPORT.TYPE.CHAT && (childVisibleActionCount > 0 || String(childReportID) === reportID);
}

/**
Expand Down Expand Up @@ -628,7 +632,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
6 changes: 5 additions & 1 deletion src/pages/home/report/ReportActionItemFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const propTypes = {
/** icon */
actorIcon: avatarPropTypes,

/** Whether the comment is a thread parent message/the first message in a thread */
isThreadParentMessage: PropTypes.bool,

...windowDimensionsPropTypes,

/** localization props */
Expand All @@ -88,6 +91,7 @@ const defaultProps = {
style: [],
delegateAccountID: 0,
actorIcon: {},
isThreadParentMessage: false,
};

function ReportActionItemFragment(props) {
Expand All @@ -113,7 +117,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) {
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)}
attachmentInfo={props.action.attachmentInfo}
pendingAction={props.action.pendingAction}
source={lodashGet(props.action, 'originalMessage.source')}
Expand Down

0 comments on commit 4abaeba

Please sign in to comment.