From 9cc67478fc26b0df9dc0fb40d3fa71314cab609e Mon Sep 17 00:00:00 2001 From: Anusha Date: Sat, 2 Sep 2023 10:02:35 +0500 Subject: [PATCH 1/5] temporary message disappears --- src/libs/ReportActionsUtils.js | 13 ++++++++++--- src/libs/ReportUtils.js | 1 + src/libs/actions/Report.js | 2 +- src/pages/home/report/ReportActionItem.js | 3 ++- src/pages/home/report/ReportActionItemFragment.js | 2 +- src/pages/home/report/ReportActionItemMessage.js | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 3ed10b865812..b81234d7c9b6 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -105,11 +105,18 @@ function isWhisperAction(action) { } /** + * + * Returns whether the comment is a thread parent message/the first message in a thread + * * @param {Object} reportAction + * @param {Number} reportID * @returns {Boolean} */ -function hasCommentThread(reportAction) { - return lodashGet(reportAction, 'childType', '') === CONST.REPORT.TYPE.CHAT && lodashGet(reportAction, 'childVisibleActionCount', 0) > 0; +function isThreadParentMessage(reportAction, reportID) { + return ( + lodashGet(reportAction, 'childType', '') === CONST.REPORT.TYPE.CHAT && + (lodashGet(reportAction, 'childVisibleActionCount', 0) > 0 || (!_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === reportID)) + ); } /** @@ -624,7 +631,7 @@ export { getLastClosedReportAction, getLatestReportActionFromOnyxData, isMoneyRequestAction, - hasCommentThread, + isThreadParentMessage, getLinkedTransactionID, getMostRecentReportActionLastModified, getReportPreviewAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ff9a5ee14519..df5c50f28522 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1797,6 +1797,7 @@ function buildOptimisticAddCommentReportAction(text, file) { attachmentInfo, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, shouldShow: true, + childType: 'chat', }, }; } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 8b898a6aaaea..ad396b8bbaac 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -926,7 +926,7 @@ function deleteReportComment(reportID, reportAction) { html: '', text: '', isEdited: true, - isDeletedParentAction: ReportActionsUtils.hasCommentThread(reportAction), + isDeletedParentAction: ReportActionsUtils.isThreadParentMessage(reportAction, reportID), }, ]; const optimisticReportActions = { diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index d5d8b38bb92c..c2f14aba54ec 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -341,6 +341,7 @@ function ReportActionItem(props) { {!props.draftMessage ? ( 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)} diff --git a/src/pages/home/report/ReportActionItemFragment.js b/src/pages/home/report/ReportActionItemFragment.js index 91ee8f7531da..e6745a89e493 100644 --- a/src/pages/home/report/ReportActionItemFragment.js +++ b/src/pages/home/report/ReportActionItemFragment.js @@ -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) { return ${props.translate('parentReportAction.deletedMessage')}`} />; } diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index 40d2d5e6d89c..6e25702c821d 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -53,7 +53,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')} From 39a1074ba34a59b5c9fa79f086035b8a4d911143 Mon Sep 17 00:00:00 2001 From: Anusha Date: Mon, 4 Sep 2023 19:45:43 +0500 Subject: [PATCH 2/5] set optimistic childType --- src/libs/ReportUtils.js | 1 - src/libs/actions/Report.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 5778450ba571..893145a8e5fa 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1805,7 +1805,6 @@ function buildOptimisticAddCommentReportAction(text, file) { attachmentInfo, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, shouldShow: true, - childType: 'chat', }, }; } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index ad396b8bbaac..c4c9b2bfcb4f 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -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: ''}}, }); } } From acb86ef4c7a6b997644fe9e70d702b0cc8ce36a5 Mon Sep 17 00:00:00 2001 From: Anusha Date: Wed, 6 Sep 2023 05:03:47 +0500 Subject: [PATCH 3/5] improve code readability --- src/libs/ReportActionsUtils.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 7582dd5258ed..768034be785a 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -113,10 +113,8 @@ function isWhisperAction(action) { * @returns {Boolean} */ function isThreadParentMessage(reportAction, reportID) { - return ( - lodashGet(reportAction, 'childType', '') === CONST.REPORT.TYPE.CHAT && - (lodashGet(reportAction, 'childVisibleActionCount', 0) > 0 || (!_.isUndefined(reportAction.childReportID) && reportAction.childReportID.toString() === reportID)) - ); + const {childType, childVisibleActionCount = 0, childReportID} = reportAction; + return childType === CONST.REPORT.TYPE.CHAT && (childVisibleActionCount > 0 || String(childReportID) === reportID); } /** From 0de1ea8e6a9b49575362447762a7a4f9158bf08e Mon Sep 17 00:00:00 2001 From: Anusha Date: Wed, 6 Sep 2023 17:59:37 +0500 Subject: [PATCH 4/5] apply suggested changes --- src/libs/ReportActionsUtils.js | 2 +- src/pages/home/report/ReportActionItemMessage.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 768034be785a..c68cbd84a9f8 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -109,7 +109,7 @@ function isWhisperAction(action) { * Returns whether the comment is a thread parent message/the first message in a thread * * @param {Object} reportAction - * @param {Number} reportID + * @param {String} reportID * @returns {Boolean} */ function isThreadParentMessage(reportAction, reportID) { diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index 6e25702c821d..bc92889158d0 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -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, }; From 326010b5edb65c395c1a0b4786c42410f1fe1ae2 Mon Sep 17 00:00:00 2001 From: Anusha Date: Sun, 10 Sep 2023 17:57:45 +0500 Subject: [PATCH 5/5] comments fixed --- src/libs/ReportActionsUtils.js | 3 +-- src/pages/home/report/ReportActionItemFragment.js | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index c68cbd84a9f8..9bb365c0f42a 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -105,14 +105,13 @@ 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 isThreadParentMessage(reportAction, reportID) { +function isThreadParentMessage(reportAction = {}, reportID) { const {childType, childVisibleActionCount = 0, childReportID} = reportAction; return childType === CONST.REPORT.TYPE.CHAT && (childVisibleActionCount > 0 || String(childReportID) === reportID); } diff --git a/src/pages/home/report/ReportActionItemFragment.js b/src/pages/home/report/ReportActionItemFragment.js index e6745a89e493..d768fcacd5b7 100644 --- a/src/pages/home/report/ReportActionItemFragment.js +++ b/src/pages/home/report/ReportActionItemFragment.js @@ -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 */ @@ -88,6 +91,7 @@ const defaultProps = { style: [], delegateAccountID: 0, actorIcon: {}, + isThreadParentMessage: false, }; function ReportActionItemFragment(props) {