diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8d24d98b19e8..f8cd86bd235d 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -822,6 +822,16 @@ function getReport(reportID) { return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}) || {}; } +/** + * Get the notification preference given a report + * + * @param {Object} report + * @returns {String} + */ +function getReportNotificationPreference(report) { + return lodashGet(report, 'notificationPreference', ''); +} + /** * Returns whether or not the author of the action is this user * @@ -2420,7 +2430,7 @@ function buildOptimisticIOUReport(payeeAccountID, payerAccountID, total, chatRep // We don't translate reportName because the server response is always in English reportName: `${payerEmail} owes ${formattedTotal}`, - notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportID: chatReportID, }; } @@ -2459,7 +2469,7 @@ function buildOptimisticExpenseReport(chatReportID, policyID, payeeAccountID, to state: CONST.REPORT.STATE.SUBMITTED, stateNum: CONST.REPORT.STATE_NUM.PROCESSING, total: storedTotal, - notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportID: chatReportID, }; } @@ -3156,7 +3166,7 @@ function buildTransactionThread(reportAction, moneyRequestReportID) { '', undefined, undefined, - CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, + CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, reportAction.reportActionID, moneyRequestReportID, ); @@ -4217,6 +4227,7 @@ export { getDisplayNamesStringFromTooltips, getReportName, getReport, + getReportNotificationPreference, getReportIDFromLink, getRouteFromLink, getDeletedParentActionMessageForChatReport, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 1de15c1184cb..181ed359db05 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -328,6 +328,10 @@ function addActions(reportID, text = '', file) { lastReadTime: currentTime, }; + if (ReportUtils.getReportNotificationPreference(ReportUtils.getReport(reportID)) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + optimisticReport.notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; + } + // Optimistically add the new actions to the store before waiting to save them to the server const optimisticReportActions = {}; if (text) { diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 48d3e8c558af..76098d72f52e 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -78,6 +78,8 @@ describe('actions/IOU', () => { const iouReport = iouReports[0]; iouReportID = iouReport.reportID; + expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + // They should be linked together expect(chatReport.participantAccountIDs).toEqual([CARLOS_ACCOUNT_ID]); expect(chatReport.iouReportID).toBe(iouReport.reportID); @@ -243,6 +245,8 @@ describe('actions/IOU', () => { const iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); iouReportID = iouReport.reportID; + expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + // They should be linked together expect(chatReport.iouReportID).toBe(iouReportID); expect(chatReport.hasOutstandingIOU).toBe(true); @@ -572,6 +576,8 @@ describe('actions/IOU', () => { const iouReport = iouReports[0]; iouReportID = iouReport.reportID; + expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + // They should be linked together expect(chatReport.participantAccountIDs).toEqual([CARLOS_ACCOUNT_ID]); expect(chatReport.iouReportID).toBe(iouReport.reportID); @@ -982,6 +988,7 @@ describe('actions/IOU', () => { expect(carlosChatReport.hasOutstandingIOU).toBe(true); expect(carlosChatReport.iouReportID).toBe(carlosIOUReport.reportID); expect(carlosIOUReport.chatReportID).toBe(carlosChatReport.reportID); + expect(carlosIOUReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); expect(julesChatReport.hasOutstandingIOU).toBe(true); expect(julesChatReport.iouReportID).toBe(julesIOUReport.reportID); @@ -990,6 +997,7 @@ describe('actions/IOU', () => { expect(vitChatReport.hasOutstandingIOU).toBe(true); expect(vitChatReport.iouReportID).toBe(vitIOUReport.reportID); expect(vitIOUReport.chatReportID).toBe(vitChatReport.reportID); + expect(carlosIOUReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); resolve(); }, @@ -2171,6 +2179,8 @@ describe('actions/IOU', () => { // Given a transaction thread thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID); + expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, callback: (val) => (reportActions = val), @@ -2248,6 +2258,9 @@ describe('actions/IOU', () => { // Given a transaction thread thread = ReportUtils.buildTransactionThread(createIOUAction); + + expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs); jest.advanceTimersByTime(10); Report.openReport(thread.reportID, userLogins, thread, createIOUAction.reportActionID); @@ -2332,6 +2345,8 @@ describe('actions/IOU', () => { jest.advanceTimersByTime(10); thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID); + expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, callback: (val) => (reportActions = val), @@ -2545,6 +2560,8 @@ describe('actions/IOU', () => { jest.advanceTimersByTime(10); thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID); + expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, callback: (val) => (reportActions = val),