diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index 2f59d580d3bd..7e44cd182c8e 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -46,7 +46,8 @@ function sortReportsByLastVisited(reports) { } /** - * Can only edit if it's a ADDCOMMENT, the author is this user and it's not a optimistic response. + * Can only edit if it's an ADDCOMMENT that is not an attachment, + * the author is this user and it's not an optimistic response. * If it's an optimistic response comment it will not have a reportActionID, * and we should wait until it does before we show the actions * @@ -61,6 +62,22 @@ function canEditReportAction(reportAction) { && !isReportMessageAttachment(lodashGet(reportAction, ['message', 0, 'text'], '')); } +/** + * Can only delete if it's an ADDCOMMENT, the author is this user and it's not an optimistic response. + * If it's an optimistic response comment it will not have a reportActionID, + * and we should wait until it does before we show the actions + * + * @param {Object} reportAction + * @param {String} sessionEmail + * @returns {Boolean} + */ +function canDeleteReportAction(reportAction) { + return reportAction.actorEmail === sessionEmail + && reportAction.reportActionID + && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT; +} + + /** * Given a collection of reports returns the most recently accessed one * @@ -90,6 +107,7 @@ export { isReportMessageAttachment, findLastAccessedReport, canEditReportAction, + canDeleteReportAction, sortReportsByLastVisited, isDefaultRoom, }; diff --git a/src/pages/home/report/ReportActionContextMenu.js b/src/pages/home/report/ReportActionContextMenu.js index c38b8d7db847..e0ec05837cdc 100755 --- a/src/pages/home/report/ReportActionContextMenu.js +++ b/src/pages/home/report/ReportActionContextMenu.js @@ -15,7 +15,7 @@ import ReportActionContextMenuItem from './ReportActionContextMenuItem'; import ReportActionPropTypes from './ReportActionPropTypes'; import Clipboard from '../../../libs/Clipboard'; import compose from '../../../libs/compose'; -import {isReportMessageAttachment, canEditReportAction} from '../../../libs/reportUtils'; +import {isReportMessageAttachment, canEditReportAction, canDeleteReportAction} from '../../../libs/reportUtils'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; import ConfirmModal from '../../../components/ConfirmModal'; import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager'; @@ -134,7 +134,7 @@ class ReportActionContextMenu extends React.Component { { text: this.props.translate('reportActionContextMenu.deleteComment'), icon: Trashcan, - shouldShow: () => canEditReportAction(this.props.reportAction), + shouldShow: () => canDeleteReportAction(this.props.reportAction), onPress: () => this.setState({isDeleteCommentConfirmModalVisible: true}), }, ];