Skip to content

Commit

Permalink
Merge pull request #3804 from rdjuric/deleteAttachments
Browse files Browse the repository at this point in the history
Add delete option to attachments
  • Loading branch information
luacmartins authored Jun 29, 2021
2 parents e0ddaa9 + c9631e4 commit a9db527
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/libs/reportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -90,6 +107,7 @@ export {
isReportMessageAttachment,
findLastAccessedReport,
canEditReportAction,
canDeleteReportAction,
sortReportsByLastVisited,
isDefaultRoom,
};
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}),
},
];
Expand Down

0 comments on commit a9db527

Please sign in to comment.