diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index eb871bcf62c1..8ce7240f7bfb 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -425,6 +425,16 @@ function getLinkedTransactionID(reportID, reportActionID) { return reportAction.originalMessage.IOUTransactionID; } +/** + * + * @param {String} reportID + * @param {String} reportActionID + * @returns {Object} + */ +function getReportAction(reportID, reportActionID) { + return lodashGet(allReportActions, [reportID, reportActionID], {}); +} + /** * @param {*} chatReportID * @param {*} iouReportID @@ -492,4 +502,5 @@ export { isMessageDeleted, isWhisperAction, isPendingRemove, + getReportAction, }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 2f6f812bdbe3..55eaee691ad9 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1633,12 +1633,18 @@ function removeEmojiReaction(reportID, originalReportAction, emoji) { /** * Calls either addEmojiReaction or removeEmojiReaction depending on if the current user has reacted to the report action. * @param {String} reportID - * @param {Object} reportAction + * @param {String} reportActionID * @param {Object} emoji * @param {number} paramSkinTone * @returns {Promise} */ -function toggleEmojiReaction(reportID, reportAction, emoji, paramSkinTone = preferredSkinTone) { +function toggleEmojiReaction(reportID, reportActionID, emoji, paramSkinTone = preferredSkinTone) { + const reportAction = ReportActionsUtils.getReportAction(reportID, reportActionID); + + if (_.isEmpty(reportAction)) { + return; + } + const message = reportAction.message[0]; const reactionObject = message.reactions && _.find(message.reactions, (reaction) => reaction.emoji === emoji.name); const skinTone = emoji.types === undefined ? null : paramSkinTone; // only use skin tone if emoji supports it diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 0a0388e414c7..b05c29804d19 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -58,7 +58,7 @@ export default [ }; const onEmojiSelected = (emoji) => { - Report.toggleEmojiReaction(reportID, reportAction, emoji); + Report.toggleEmojiReaction(reportID, reportAction.reportActionID, emoji); closeContextMenu(); }; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 926774dfc755..c8cf023a6138 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -207,7 +207,7 @@ function ReportActionItem(props) { const toggleReaction = useCallback( (emoji) => { - Report.toggleEmojiReaction(props.report.reportID, props.action, emoji); + Report.toggleEmojiReaction(props.report.reportID, props.action.reportActionID, emoji); }, [props.report, props.action], ); diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js index e98a5249187f..5ebffff507b8 100644 --- a/tests/actions/ReportTest.js +++ b/tests/actions/ReportTest.js @@ -659,7 +659,7 @@ describe('actions/Report', () => { const resultAction = _.first(_.values(reportActions)); // Add a reaction to the comment - Report.toggleEmojiReaction(REPORT_ID, resultAction, EMOJI); + Report.toggleEmojiReaction(REPORT_ID, resultAction.reportActionID, EMOJI); return waitForPromisesToResolve(); }) .then(() => { @@ -668,7 +668,7 @@ describe('actions/Report', () => { // Now we toggle the reaction while the skin tone has changed. // As the emoji doesn't support skin tones, the emoji // should get removed instead of added again. - Report.toggleEmojiReaction(REPORT_ID, resultAction, EMOJI, 2); + Report.toggleEmojiReaction(REPORT_ID, resultAction.reportActionID, EMOJI, 2); return waitForPromisesToResolve(); }) .then(() => {