-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Pass reportActions as param to shouldShowReportActionNotification #95318
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
base: main
Are you sure you want to change the base?
Changes from all commits
0fac7d0
0e9cb8f
ec486e7
3f1c61a
2da1626
e44f344
b43d920
afe9bd1
59ef281
f758014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {getOneTransactionThreadReportID} from '@libs/ReportActionsUtils'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import useNetwork from './useNetwork'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| function useOneTransactionThreadReportID(reportID: string | undefined) { | ||
| const {isOffline} = useNetwork(); | ||
| const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); | ||
| const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`); | ||
| const [oneTransactionThreadReportID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { | ||
| selector: (actions) => getOneTransactionThreadReportID(report, chatReport, actions, isOffline), | ||
| }); | ||
|
|
||
| return oneTransactionThreadReportID; | ||
| } | ||
|
|
||
| export default useOneTransactionThreadReportID; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| import Log from '@libs/Log'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {getIsOffline} from '@libs/NetworkState'; | ||
| import * as ReportActionUtils from '@libs/ReportActionsUtils'; | ||
|
|
||
| import * as Report from '@userActions/Report'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Report as ReportType, ReportActions} from '@src/types/onyx'; | ||
|
|
||
| import type {PushPayload} from '@ua/react-native-airship'; | ||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
|
|
||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
|
|
@@ -21,6 +25,22 @@ Onyx.connectWithoutView({ | |
| }, | ||
| }); | ||
|
|
||
| // We do not depend on updates on the UI for notifications, so we can use `connectWithoutView` here. | ||
| let allReportActions: OnyxCollection<ReportActions>; | ||
| Onyx.connectWithoutView({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment to indicate why it's OK to use this instead of using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reuse the comment from the above one
|
||
| key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => (allReportActions = value), | ||
| }); | ||
|
|
||
| // We do not depend on updates on the UI for notifications, so we can use `connectWithoutView` here. | ||
| let allReports: OnyxCollection<ReportType>; | ||
| Onyx.connectWithoutView({ | ||
| key: ONYXKEYS.COLLECTION.REPORT, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => (allReports = value), | ||
| }); | ||
|
|
||
| /** | ||
| * Returns whether the given Airship notification should be shown depending on the current state of the app | ||
| */ | ||
|
|
@@ -37,7 +57,12 @@ export default function shouldShowPushNotification(pushPayload: PushPayload): bo | |
| shouldShow = true; | ||
| } else { | ||
| const reportAction = ReportActionUtils.getLatestReportActionFromOnyxData(data.onyxData ?? null); | ||
| shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), currentUserAccountID, reportAction, true); | ||
| const topmostReportID = Navigation.getTopmostReportId(); | ||
| const topmostReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${topmostReportID}`]; | ||
| const topmostChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${topmostReport?.chatReportID}`]; | ||
| const topmostReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${topmostReportID}`]; | ||
| const topmostOneTransactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(topmostReport, topmostChatReport, topmostReportActions, getIsOffline()); | ||
| shouldShow = Report.shouldShowReportActionNotification(String(data.reportID), topmostOneTransactionThreadReportID, currentUserAccountID, reportAction, true); | ||
| } | ||
|
|
||
| Log.info(`[PushNotification] ${shouldShow ? 'Showing' : 'Not showing'} notification`); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.