From d71605ef0b87c9dc063fc8aaf0a9560f6837d7f4 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 16 Oct 2023 16:47:07 +0200 Subject: [PATCH 1/9] update norif. pref. --- src/libs/ReportUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0b7bbfd61461..130a0ae5f9b2 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2162,7 +2162,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, }; } @@ -2201,7 +2201,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, }; } @@ -2896,7 +2896,7 @@ function buildTransactionThread(reportAction, moneyRequestReportID) { '', undefined, undefined, - CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, + CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, reportAction.reportActionID, moneyRequestReportID, ); From 606a6a3628efed60e7f287a61fdf92f99af41973 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 19 Oct 2023 13:32:49 +0200 Subject: [PATCH 2/9] update notif.pref. --- src/libs/actions/Report.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c9f3ba6318db..0c2da46ebc05 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -329,6 +329,12 @@ function addActions(reportID, text = '', file) { isLastMessageDeletedParentAction: null, }; + const report = ReportUtils.getReport(reportID); + + if (lodashGet(report, 'notificationPreference', null) === 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) { From 8907434ed3ae175ba834b05468705cf4c97132cf Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 19 Oct 2023 16:00:27 +0200 Subject: [PATCH 3/9] create getReportNotificationPreference --- src/libs/ReportUtils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d039dd5c6a2f..3eb3ef6d6495 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -766,6 +766,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', ''); +} + /** * Can only delete if the author is this user and the action is an ADDCOMMENT action or an IOU action in an unsettled report, or if the user is a * policy admin @@ -3981,6 +3991,7 @@ export { getDisplayNamesWithTooltips, getReportName, getReport, + getReportNotificationPreference, getReportIDFromLink, getRouteFromLink, getDeletedParentActionMessageForChatReport, From 5699f67afdda9fc38329796e57667b88f4171f3a Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 19 Oct 2023 16:00:38 +0200 Subject: [PATCH 4/9] implement getReportNotificationPreference --- src/libs/actions/Report.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 8497ab4f1ef5..e6de9dd1fe4d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -329,9 +329,7 @@ function addActions(reportID, text = '', file) { isLastMessageDeletedParentAction: null, }; - const report = ReportUtils.getReport(reportID); - - if (lodashGet(report, 'notificationPreference', null) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + if (ReportUtils.getReportNotificationPreference(ReportUtils.getReport(reportID)) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { optimisticReport.notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; } From 834795765eb09d98605681076acc111092f5c9a9 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 19 Oct 2023 17:56:11 +0200 Subject: [PATCH 5/9] add notif. pref. test for buildTransactionThread --- tests/actions/IOUTest.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 0ee3b0c0b357..36a933f1a547 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1702,6 +1702,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), @@ -1779,6 +1781,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); @@ -1863,6 +1868,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), @@ -2076,6 +2083,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), From 4ff06364324c9802b86393e2a17009ad365e9906 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 19 Oct 2023 18:15:35 +0200 Subject: [PATCH 6/9] add notif. pref. test for buildOptimisticIOUReport and buildOptimisticExpenseReport --- tests/actions/IOUTest.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 36a933f1a547..40ca7082a8f1 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); @@ -242,6 +244,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); @@ -570,6 +574,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); From 6551e7ef049be10b3691037eec5b780cf2a864e5 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 19 Oct 2023 18:20:13 +0200 Subject: [PATCH 7/9] cover split bill case --- tests/actions/IOUTest.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 40ca7082a8f1..1e9e09d30ff3 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -984,6 +984,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); @@ -992,6 +993,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(); }, From d3daf618b68941007ad1e5fd843c303111f73ed0 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 20 Oct 2023 11:58:21 +0200 Subject: [PATCH 8/9] use reportID in getReportNotificationPreference --- src/libs/ReportUtils.js | 8 ++++---- src/libs/actions/Report.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 064b475a0aaa..6934abaa86b3 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -778,13 +778,13 @@ function getReport(reportID) { } /** - * Get the notification preference given a report + * Get the notification preference given a reportID * - * @param {Object} report + * @param {String} reportID * @returns {String} */ -function getReportNotificationPreference(report) { - return lodashGet(report, 'notificationPreference', ''); +function getReportNotificationPreference(reportID) { + return lodashGet(getReport(reportID), 'notificationPreference', ''); } /** diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index d505d8d7268f..ecfe1e077a5e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -329,7 +329,7 @@ function addActions(reportID, text = '', file) { isLastMessageDeletedParentAction: null, }; - if (ReportUtils.getReportNotificationPreference(ReportUtils.getReport(reportID)) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + if (ReportUtils.getReportNotificationPreference(reportID) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { optimisticReport.notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; } From 8484427138e3807176fbd9bae70b2bf717e3228f Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 20 Oct 2023 11:58:37 +0200 Subject: [PATCH 9/9] Revert "use reportID in getReportNotificationPreference" This reverts commit d3daf618b68941007ad1e5fd843c303111f73ed0. --- src/libs/ReportUtils.js | 8 ++++---- src/libs/actions/Report.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 6934abaa86b3..064b475a0aaa 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -778,13 +778,13 @@ function getReport(reportID) { } /** - * Get the notification preference given a reportID + * Get the notification preference given a report * - * @param {String} reportID + * @param {Object} report * @returns {String} */ -function getReportNotificationPreference(reportID) { - return lodashGet(getReport(reportID), 'notificationPreference', ''); +function getReportNotificationPreference(report) { + return lodashGet(report, 'notificationPreference', ''); } /** diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index ecfe1e077a5e..d505d8d7268f 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -329,7 +329,7 @@ function addActions(reportID, text = '', file) { isLastMessageDeletedParentAction: null, }; - if (ReportUtils.getReportNotificationPreference(reportID) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + if (ReportUtils.getReportNotificationPreference(ReportUtils.getReport(reportID)) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { optimisticReport.notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; }