diff --git a/src/CONST.js b/src/CONST.js index 6d16d862b46d..96fe7084239e 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -730,6 +730,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 7faf3db8a358..20f0add4641d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -167,7 +167,7 @@ function getSimplifiedReportObject(report) { const oldPolicyName = lodashGet(report, ['reportNameValuePairs', 'oldPolicyName'], '').toString(); const lastActorEmail = lodashGet(report, 'lastActionActorEmail', ''); - const notificationPreference = lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], 'daily'); + const notificationPreference = 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 const visibility = lodashGet(report, ['reportNameValuePairs', 'visibility']); @@ -1312,14 +1312,26 @@ function syncChatAndIOUReports(chatReport, iouReport) { } /** - * Updates a user's notification preferences for a chat room - * * @param {Number} reportID - * @param {String} notificationPreference + * @param {String} previousValue + * @param {String} newValue */ -function updateNotificationPreference(reportID, notificationPreference) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {notificationPreference}); - DeprecatedAPI.Report_UpdateNotificationPreference({reportID, notificationPreference}); +function updateNotificationPreference(reportID, previousValue, newValue) { + const optimisticData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {notificationPreference: newValue}, + }, + ]; + const failureData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {notificationPreference: previousValue}, + }, + ]; + API.write('UpdateReportNotificationPreference', {reportID, notificationPreference: newValue}, {optimisticData, failureData}); } /** 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, 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, ); }}