Skip to content

Commit 693389c

Browse files
authored
Merge pull request Expensify#80493 from linhvovan29546/fix/73648-remove-onyxkey-session-in-report-part7
[Part 7]Remove Onyx.connect() for the key: ONYXKEYS.SESSION in src/libs/actions/Report.ts
2 parents 9d572f5 + 94f7200 commit 693389c

28 files changed

Lines changed: 483 additions & 195 deletions

src/CONST/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8274,6 +8274,9 @@ const CONST = {
82748274
REANIMATED_MODAL: {
82758275
BACKDROP: 'ReanimatedModal-Backdrop',
82768276
},
8277+
SHARE_DETAIL: {
8278+
DISMISS_KEYBOARD_BUTTON: 'ShareDetail-DismissKeyboardButton',
8279+
},
82778280
REQUEST_STEP: {
82788281
SCAN: {
82798282
MULTI_SCAN: 'Scan-MultiScan',

src/libs/Navigation/AppNavigator/AuthScreens.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ const loadWorkspaceSplitNavigator = () => require<ReactComponentModule>('./Navig
9696
const loadDomainSplitNavigator = () => require<ReactComponentModule>('./Navigators/DomainSplitNavigator').default;
9797
const loadSearchNavigator = () => require<ReactComponentModule>('./Navigators/SearchFullscreenNavigator').default;
9898

99-
function initializePusher() {
99+
function initializePusher(currentUserAccountID?: number) {
100100
return Pusher.init({
101101
appKey: CONFIG.PUSHER.APP_KEY,
102102
cluster: CONFIG.PUSHER.CLUSTER,
103103
authEndpoint: `${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/AuthenticatePusher?`,
104104
}).then(() => {
105-
User.subscribeToUserEvents();
105+
User.subscribeToUserEvents(currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID);
106106
});
107107
}
108108

@@ -201,9 +201,9 @@ function AuthScreens() {
201201
return;
202202
}
203203
// This means sign in in RHP was successful, so we can subscribe to user events
204-
initializePusher();
204+
initializePusher(session?.accountID);
205205
// eslint-disable-next-line react-hooks/exhaustive-deps
206-
}, [session]);
206+
}, [session?.accountID]);
207207

208208
useAutoUpdateTimezone();
209209

@@ -239,7 +239,7 @@ function AuthScreens() {
239239
parentSpan: getSpan(CONST.TELEMETRY.SPAN_BOOTSPLASH.ROOT),
240240
});
241241
PusherConnectionManager.init();
242-
initializePusher().finally(() => {
242+
initializePusher(session?.accountID).finally(() => {
243243
endSpan(CONST.TELEMETRY.SPAN_NAVIGATION.PUSHER_INIT);
244244
});
245245

src/libs/Notification/PushNotification/shouldShowPushNotification.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import type {PushPayload} from '@ua/react-native-airship';
2+
import Onyx from 'react-native-onyx';
23
import Log from '@libs/Log';
34
import * as ReportActionUtils from '@libs/ReportActionsUtils';
45
import * as Report from '@userActions/Report';
6+
import CONST from '@src/CONST';
7+
import ONYXKEYS from '@src/ONYXKEYS';
58
import parsePushNotificationPayload from './parsePushNotificationPayload';
69

10+
// We do not depend on updates on the UI for notifications, so we can use `connectWithoutView` here.
11+
let currentUserAccountID = -1;
12+
Onyx.connectWithoutView({
13+
key: ONYXKEYS.SESSION,
14+
callback: (value) => {
15+
currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
16+
},
17+
});
18+
719
/**
820
* Returns whether the given Airship notification should be shown depending on the current state of the app
921
*/
@@ -20,7 +32,7 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo
2032
shouldShow = true;
2133
} else {
2234
const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData ?? null);
23-
shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), reportAction, true);
35+
shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), currentUserAccountID, reportAction, true);
2436
}
2537

2638
Log.info(`[PushNotification] ${shouldShow ? 'Showing' : 'Not showing'} notification`);

src/libs/actions/IOU/Hold.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ function putOnHold(transactionID: string, comment: string, initialReportID: stri
310310
API.write(WRITE_COMMANDS.HOLD_MONEY_REQUEST, params, {optimisticData, successData, failureData});
311311

312312
const currentReportID = getDisplayedReportID(reportID);
313-
Navigation.setNavigationActionToMicrotaskQueue(() => notifyNewAction(currentReportID, userAccountID));
313+
Navigation.setNavigationActionToMicrotaskQueue(() => notifyNewAction(currentReportID, undefined, true));
314314
}
315315

316316
function putTransactionsOnHold(transactionsID: string[], comment: string, reportID: string, ancestors: Ancestor[] = []) {
@@ -518,7 +518,7 @@ function unholdRequest(transactionID: string, reportID: string, policy: OnyxEntr
518518
);
519519

520520
const currentReportID = getDisplayedReportID(reportID);
521-
notifyNewAction(currentReportID, userAccountID);
521+
notifyNewAction(currentReportID, undefined, true);
522522
}
523523

524524
export {putOnHold, putTransactionsOnHold, unholdRequest};

src/libs/actions/IOU/SendInvoice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ function sendInvoice({
813813
isInvoice: true,
814814
});
815815

816-
notifyNewAction(invoiceRoom.reportID, currentUserAccountID);
816+
notifyNewAction(invoiceRoom.reportID, undefined, true);
817817
}
818818

819819
export {getReceiverType, getSendInvoiceInformation, sendInvoice};

src/libs/actions/IOU/SendMoney.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function getSendMoneyParams({
475475
}
476476

477477
/**
478-
* @param managerID - Account ID of the person sending the money
478+
* @param currentUserAccountID - Account ID of the person sending the money
479479
* @param recipient - The user receiving the money
480480
*/
481481
function sendMoneyElsewhere(
@@ -484,7 +484,7 @@ function sendMoneyElsewhere(
484484
amount: number,
485485
currency: string,
486486
comment: string,
487-
managerID: number,
487+
currentUserAccountID: number,
488488
recipient: Participant,
489489
created?: string,
490490
merchant?: string,
@@ -497,7 +497,7 @@ function sendMoneyElsewhere(
497497
currency,
498498
commentParam: comment,
499499
paymentMethodType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
500-
managerID,
500+
managerID: currentUserAccountID,
501501
recipient,
502502
created,
503503
merchant,
@@ -507,11 +507,11 @@ function sendMoneyElsewhere(
507507
API.write(WRITE_COMMANDS.SEND_MONEY_ELSEWHERE, params, {optimisticData, successData, failureData});
508508

509509
dismissModalAndOpenReportInInboxTab(params.chatReportID);
510-
notifyNewAction(params.chatReportID, managerID);
510+
notifyNewAction(params.chatReportID, undefined, true);
511511
}
512512

513513
/**
514-
* @param managerID - Account ID of the person sending the money
514+
* @param currentUserAccountID - Account ID of the person sending the money
515515
* @param recipient - The user receiving the money
516516
*/
517517
function sendMoneyWithWallet(
@@ -520,7 +520,7 @@ function sendMoneyWithWallet(
520520
amount: number,
521521
currency: string,
522522
comment: string,
523-
managerID: number,
523+
currentUserAccountID: number,
524524
recipient: Participant | OptionData,
525525
created?: string,
526526
merchant?: string,
@@ -533,7 +533,7 @@ function sendMoneyWithWallet(
533533
currency,
534534
commentParam: comment,
535535
paymentMethodType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY,
536-
managerID,
536+
managerID: currentUserAccountID,
537537
recipient,
538538
created,
539539
merchant,
@@ -543,7 +543,7 @@ function sendMoneyWithWallet(
543543
API.write(WRITE_COMMANDS.SEND_MONEY_WITH_WALLET, params, {optimisticData, successData, failureData});
544544

545545
dismissModalAndOpenReportInInboxTab(params.chatReportID);
546-
notifyNewAction(params.chatReportID, managerID);
546+
notifyNewAction(params.chatReportID, undefined, true);
547547
}
548548

549549
export {sendMoneyElsewhere, sendMoneyWithWallet};

src/libs/actions/IOU/Split.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function splitBill({
218218

219219
dismissModalAndOpenReportInInboxTab(existingSplitChatReportID);
220220

221-
notifyNewAction(splitData.chatReportID, currentUserAccountID);
221+
notifyNewAction(splitData.chatReportID, undefined, true);
222222
}
223223

224224
/**
@@ -308,7 +308,7 @@ function splitBillAndOpenReport({
308308
InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));
309309

310310
dismissModalAndOpenReportInInboxTab(splitData.chatReportID);
311-
notifyNewAction(splitData.chatReportID, currentUserAccountID);
311+
notifyNewAction(splitData.chatReportID, undefined, true);
312312
}
313313

314314
/**
@@ -679,7 +679,7 @@ function startSplitBill({
679679
API.write(WRITE_COMMANDS.START_SPLIT_BILL, parameters, {optimisticData, successData, failureData});
680680

681681
Navigation.dismissModalWithReport({reportID: splitChatReport.reportID});
682-
notifyNewAction(splitChatReport.reportID, currentUserAccountID);
682+
notifyNewAction(splitChatReport.reportID, undefined, true);
683683

684684
// Return the split transactionID for testing purpose
685685
return {splitTransactionID: splitTransaction.transactionID};
@@ -991,7 +991,7 @@ function completeSplitBill(
991991
// eslint-disable-next-line @typescript-eslint/no-deprecated
992992
InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));
993993
dismissModalAndOpenReportInInboxTab(chatReportID);
994-
notifyNewAction(chatReportID, sessionAccountID);
994+
notifyNewAction(chatReportID, undefined, true);
995995
}
996996

997997
function updateSplitTransactions({

src/libs/actions/IOU/index.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,7 +5206,7 @@ function updateMoneyRequestDate({
52065206
removeTransactionFromDuplicateTransactionViolation(data.onyxData, transactionID, transactions, transactionViolations);
52075207
}
52085208
const {params, onyxData} = data;
5209-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5209+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
52105210
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DATE, params, onyxData);
52115211
}
52125212

@@ -5354,7 +5354,7 @@ function updateMoneyRequestMerchant({
53545354
});
53555355
}
53565356
const {params, onyxData} = data;
5357-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5357+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
53585358
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_MERCHANT, params, onyxData);
53595359
}
53605360

@@ -5457,7 +5457,7 @@ function updateMoneyRequestTag({
54575457
isASAPSubmitBetaEnabled,
54585458
iouReportNextStep: parentReportNextStep,
54595459
});
5460-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5460+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
54615461
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_TAG, params, onyxData);
54625462
}
54635463

@@ -5504,7 +5504,7 @@ function updateMoneyRequestTaxAmount({
55045504
iouReportNextStep: parentReportNextStep,
55055505
});
55065506
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_TAX_AMOUNT, params, onyxData);
5507-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5507+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
55085508
}
55095509

55105510
type UpdateMoneyRequestTaxRateParams = {
@@ -5559,7 +5559,7 @@ function updateMoneyRequestTaxRate({
55595559
});
55605560

55615561
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_TAX_RATE, params, onyxData);
5562-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5562+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
55635563
}
55645564

55655565
type UpdateMoneyRequestDistanceParams = {
@@ -5731,7 +5731,7 @@ function updateMoneyRequestCategory({
57315731
hash,
57325732
iouReportNextStep: parentReportNextStep,
57335733
});
5734-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5734+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
57355735
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_CATEGORY, params, onyxData);
57365736
}
57375737

@@ -5786,7 +5786,7 @@ function updateMoneyRequestDescription({
57865786
}
57875787
const {params, onyxData} = data;
57885788
params.description = parsedComment;
5789-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5789+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
57905790
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DESCRIPTION, params, onyxData);
57915791
}
57925792

@@ -5860,7 +5860,7 @@ function updateMoneyRequestDistanceRate({
58605860
// `taxAmount` & `taxCode` only needs to be updated in the optimistic data, so we need to remove them from the params
58615861
const {taxAmount, taxCode, ...paramsWithoutTaxUpdated} = params;
58625862
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DISTANCE_RATE, paramsWithoutTaxUpdated, onyxData);
5863-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
5863+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
58645864
}
58655865

58665866
const getConvertTrackedExpenseInformation = (
@@ -6740,7 +6740,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation): {iouRep
67406740
if (activeReportID && !isMoneyRequestReport) {
67416741
Navigation.setNavigationActionToMicrotaskQueue(() =>
67426742
setTimeout(() => {
6743-
notifyNewAction(activeReportID, payeeAccountID, reportPreviewAction);
6743+
notifyNewAction(activeReportID, reportPreviewAction, payeeAccountID === currentUserAccountIDParam);
67446744
}, CONST.TIMING.NOTIFY_NEW_ACTION_DELAY),
67456745
);
67466746
}
@@ -6857,7 +6857,7 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf
68576857
handleNavigateAfterExpenseCreate({activeReportID, transactionID: transaction.transactionID, isFromGlobalCreate});
68586858

68596859
if (activeReportID) {
6860-
notifyNewAction(activeReportID, payeeAccountID);
6860+
notifyNewAction(activeReportID, undefined, payeeAccountID === currentUserAccountIDParam);
68616861
}
68626862
}
68636863

@@ -7218,7 +7218,7 @@ function trackExpense(params: CreateTrackExpenseParams) {
72187218
});
72197219
}
72207220

7221-
notifyNewAction(activeReportID, payeeAccountID);
7221+
notifyNewAction(activeReportID, undefined, payeeAccountID === currentUserAccountIDParam);
72227222
}
72237223

72247224
function getOrCreateOptimisticSplitChatReport(existingSplitChatReportID: string | undefined, participants: Participant[], participantAccountIDs: number[], currentUserAccountID: number) {
@@ -8077,7 +8077,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
80778077
}
80788078

80798079
if (!isMoneyRequestReport) {
8080-
notifyNewAction(activeReportID, userAccountID);
8080+
notifyNewAction(activeReportID, undefined, true);
80818081
}
80828082
}
80838083

@@ -8156,7 +8156,7 @@ function updateMoneyRequestAmountAndCurrency({
81568156
removeTransactionFromDuplicateTransactionViolation(data.onyxData, transactionID, transactions, transactionViolations);
81578157
}
81588158
const {params, onyxData} = data;
8159-
notifyNewAction(Navigation.getSearchTopmostReportId(), currentUserAccountIDParam);
8159+
notifyNewAction(Navigation.getSearchTopmostReportId(), undefined, true);
81608160
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_AMOUNT_AND_CURRENCY, params, onyxData);
81618161
}
81628162

@@ -11336,7 +11336,8 @@ function cancelPayment(
1133611336
},
1133711337
{optimisticData, successData, failureData},
1133811338
);
11339-
notifyNewAction(expenseReport.reportID, userAccountID);
11339+
11340+
notifyNewAction(expenseReport.reportID, undefined, true);
1134011341
}
1134111342

1134211343
/**
@@ -11419,7 +11420,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) {
1141911420

1142011421
playSound(SOUNDS.SUCCESS);
1142111422
API.write(apiCommand, payMoneyRequestParams, {optimisticData, successData, failureData});
11422-
notifyNewAction(!full ? (Navigation.getTopmostReportId() ?? iouReport?.reportID) : iouReport?.reportID, userAccountID);
11423+
notifyNewAction(!full ? (Navigation.getTopmostReportId() ?? iouReport?.reportID) : iouReport?.reportID, undefined, true);
1142311424
return payMoneyRequestParams.optimisticHoldReportID;
1142411425
}
1142511426

@@ -13029,7 +13030,7 @@ function markRejectViolationAsResolved(transactionID: string, reportID?: string)
1302913030
});
1303013031

1303113032
const currentReportID = getDisplayedReportID(reportID);
13032-
notifyNewAction(currentReportID, userAccountID);
13033+
notifyNewAction(currentReportID, undefined, true);
1303313034
}
1303413035

1303513036
function initSplitExpenseItemData(

src/libs/actions/Report/SuggestedFollowup.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function resolveSuggestedFollowup(
3131
reportAction: OnyxEntry<ReportAction>,
3232
selectedFollowup: Followup,
3333
timezoneParam: Timezone,
34+
currentUserAccountID: number,
3435
ancestors: Ancestor[] = [],
3536
) {
3637
const reportID = report?.reportID;
@@ -52,7 +53,7 @@ function resolveSuggestedFollowup(
5253
});
5354

5455
if (!selectedFollowup.response) {
55-
addComment(report, notifyReportID ?? reportID, ancestors, selectedFollowup.text, timezoneParam);
56+
addComment({report, notifyReportID: notifyReportID ?? reportID, ancestors, text: selectedFollowup.text, timezoneParam, currentUserAccountID});
5657
return;
5758
}
5859

@@ -61,9 +62,19 @@ function resolveSuggestedFollowup(
6162
const optimisticConciergeReportActionID = rand64();
6263

6364
// Post user's comment immediately
64-
addComment(report, notifyReportID ?? reportID, ancestors, selectedFollowup.text, timezoneParam, false, false, {
65-
optimisticConciergeReportActionID,
66-
pregeneratedResponse: selectedFollowup.response,
65+
addComment({
66+
report,
67+
notifyReportID: notifyReportID ?? reportID,
68+
ancestors,
69+
text: selectedFollowup.text,
70+
timezoneParam,
71+
currentUserAccountID,
72+
shouldPlaySound: false,
73+
isInSidePanel: false,
74+
pregeneratedResponseParams: {
75+
optimisticConciergeReportActionID,
76+
pregeneratedResponse: selectedFollowup.response,
77+
},
6778
});
6879

6980
const optimisticConciergeAction = buildOptimisticAddCommentReportAction(

0 commit comments

Comments
 (0)