From c8fb89d32ccfc3a522f96bdb86bc06d0122b5495 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 20 Jun 2022 15:12:54 -0600 Subject: [PATCH 1/6] Remove the old API method --- src/libs/actions/Report.js | 10 ++++++++-- src/libs/deprecatedAPI.js | 14 -------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index f529931b5c80..574ce9893840 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1314,8 +1314,14 @@ function syncChatAndIOUReports(chatReport, iouReport) { * @param {String} notificationPreference */ function updateNotificationPreference(reportID, notificationPreference) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {notificationPreference}); - DeprecatedAPI.Report_UpdateNotificationPreference({reportID, notificationPreference}); + const optimisticData = [ + { + onyxMethod: 'merge', + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {notificationPreference}, + }, + ]; + API.write('UpdateReportNotificationPreference', {reportID, notificationPreference}, {optimisticData}); } /** diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 67333741f0a7..24a9c3e9c73c 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -368,19 +368,6 @@ function Report_UpdateLastRead(parameters) { return Network.post(commandName, parameters); } -/** - * @param {Object} parameters - * @param {Number} parameters.reportID - * @param {String} parameters.notificationPreference - * @returns {Promise} - * - */ -function Report_UpdateNotificationPreference(parameters) { - const commandName = 'Report_UpdateNotificationPreference'; - requireParameters(['reportID', 'notificationPreference'], parameters, commandName); - return Network.post(commandName, parameters); -} - /** * @param {Object} parameters * @param {String} parameters.email @@ -956,7 +943,6 @@ export { Report_TogglePinned, Report_EditComment, Report_UpdateLastRead, - Report_UpdateNotificationPreference, ResendValidateCode, ResetPassword, SetNameValuePair, From 8572e2b119649ca8d7dafc8815f05eaf270d02fc Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 20 Jun 2022 15:45:56 -0600 Subject: [PATCH 2/6] Replace string with constant --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 574ce9893840..476114b023a1 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -168,7 +168,7 @@ function getSimplifiedReportObject(report) { const lastActorEmail = lodashGet(report, 'lastActionActorEmail', ''); const notificationPreference = ReportUtils.isChatRoom({chatType}) - ? lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], 'daily') + ? lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], CONST.REPORT.NOTIFICATION_PREFERENCE.DAILY) : ''; // Used for User Created Policy Rooms, will denote how access to a chat room is given among workspace members From cec863d507052f35aabd8381b0ccfc5c756f43cf Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 21 Jun 2022 10:30:40 -0600 Subject: [PATCH 3/6] Set failure data to revert the notification preference --- src/libs/actions/Report.js | 19 ++++++++++--------- src/pages/ReportSettingsPage.js | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 476114b023a1..c200bc00d0c0 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1307,21 +1307,22 @@ function syncChatAndIOUReports(chatReport, iouReport) { Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, simplifiedReport); } -/** - * Updates a user's notification preferences for a chat room - * - * @param {Number} reportID - * @param {String} notificationPreference - */ -function updateNotificationPreference(reportID, notificationPreference) { +function updateNotificationPreference(reportID, previousValue, newValue) { const optimisticData = [ { onyxMethod: 'merge', key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: {notificationPreference}, + value: {notificationPreference: newValue}, + }, + ]; + const failureData = [ + { + onyxMethod: 'merge', + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {notificationPreference: previousValue}, }, ]; - API.write('UpdateReportNotificationPreference', {reportID, notificationPreference}, {optimisticData}); + API.write('UpdateReportNotificationPreference', {reportID, notificationPreference: newValue}, {optimisticData, failureData}); } /** diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 7cb8e62e72f5..5d9881feb60b 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -171,6 +171,7 @@ class ReportSettingsPage extends Component { onInputChange={(notificationPreference) => { Report.updateNotificationPreference( this.props.report.reportID, + this.props.report.notificationPreference, notificationPreference, ); }} From 7cb3aad73e8a0ac061fd3a226195be5034c43c99 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 21 Jun 2022 12:58:08 -0600 Subject: [PATCH 4/6] Use a constant for onyx methods --- src/CONST.js | 6 ++++++ src/libs/actions/Report.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index e5b6657ebddd..403e62e639bc 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -711,6 +711,12 @@ const CONST = { // There's a limit of 60k characters in Auth - https://github.com/Expensify/Auth/blob/198d59547f71fdee8121325e8bc9241fc9c3236a/auth/lib/Request.h#L28 MAX_COMMENT_LENGTH: 60000, + + ONYX: { + METHOD: { + MERGE: 'merge', + }, + }, }; export default CONST; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c200bc00d0c0..fb7cb8fb71fb 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1310,14 +1310,14 @@ function syncChatAndIOUReports(chatReport, iouReport) { function updateNotificationPreference(reportID, previousValue, newValue) { const optimisticData = [ { - onyxMethod: 'merge', + onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: {notificationPreference: newValue}, }, ]; const failureData = [ { - onyxMethod: 'merge', + onyxMethod: CONST.ONYX.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: {notificationPreference: previousValue}, }, From 882d50fbd8923bbf080d003cff4c876168ed5b1f Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 5 Jul 2022 15:49:52 -0600 Subject: [PATCH 5/6] Add missing JS docs --- src/libs/actions/Report.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index fb7cb8fb71fb..522d2a8963f1 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1307,6 +1307,11 @@ function syncChatAndIOUReports(chatReport, iouReport) { Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, simplifiedReport); } +/** + * @param {String} reportID + * @param {String} previousValue + * @param {String} newValue + */ function updateNotificationPreference(reportID, previousValue, newValue) { const optimisticData = [ { From 841baf39fd2c4225d3358df4e921aded20773e63 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 6 Jul 2022 09:19:15 -0600 Subject: [PATCH 6/6] Update src/libs/actions/Report.js Co-authored-by: Rory Abraham <47436092+roryabraham@users.noreply.github.com> --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index eb711508dce8..20f0add4641d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1312,7 +1312,7 @@ function syncChatAndIOUReports(chatReport, iouReport) { } /** - * @param {String} reportID + * @param {Number} reportID * @param {String} previousValue * @param {String} newValue */