Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make optimistic requests/IOUs/expense reports “hidden” #29681

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d71605e
update norif. pref.
rezkiy37 Oct 16, 2023
bdbe237
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 17, 2023
f64e34b
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 18, 2023
606a6a3
update notif.pref.
rezkiy37 Oct 19, 2023
5722528
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 19, 2023
8907434
create getReportNotificationPreference
rezkiy37 Oct 19, 2023
5699f67
implement getReportNotificationPreference
rezkiy37 Oct 19, 2023
8347957
add notif. pref. test for buildTransactionThread
rezkiy37 Oct 19, 2023
4ff0636
add notif. pref. test for buildOptimisticIOUReport and buildOptimisti…
rezkiy37 Oct 19, 2023
6551e7e
cover split bill case
rezkiy37 Oct 19, 2023
e5c0514
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 20, 2023
d3daf61
use reportID in getReportNotificationPreference
rezkiy37 Oct 20, 2023
8484427
Revert "use reportID in getReportNotificationPreference"
rezkiy37 Oct 20, 2023
d00caf7
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 30, 2023
e147351
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 31, 2023
0ecf54e
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Nov 6, 2023
f06d7b2
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
rezkiy37 marked this conversation as resolved.
Show resolved Hide resolved
return lodashGet(report, 'notificationPreference', '');
}

/**
* Returns whether or not the author of the action is this user
*
Expand Down Expand Up @@ -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,
mountiny marked this conversation as resolved.
Show resolved Hide resolved
parentReportID: chatReportID,
};
}
Expand Down Expand Up @@ -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,
};
}
Expand Down Expand Up @@ -3156,7 +3166,7 @@ function buildTransactionThread(reportAction, moneyRequestReportID) {
'',
undefined,
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
reportAction.reportActionID,
moneyRequestReportID,
);
Expand Down Expand Up @@ -4217,6 +4227,7 @@ export {
getDisplayNamesStringFromTooltips,
getReportName,
getReport,
getReportNotificationPreference,
getReportIDFromLink,
getRouteFromLink,
getDeletedParentActionMessageForChatReport,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions tests/actions/IOUTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
},
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
Loading