-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Support transaction push notifications #59308
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
af77332
add transaction push notification type
arosiclair 6afda36
handle transaction push notifications
arosiclair b40c7cd
Merge branch 'main' of github.com:Expensify/App into arosiclair-trans…
arosiclair 8a7c7df
handle undefined push notification data
arosiclair e6546f9
always show transaction push notifications
arosiclair ae38c6d
fix event handler types
arosiclair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; | |
import ROUTES from '@src/ROUTES'; | ||
import type {OnyxUpdatesFromServer} from '@src/types/onyx'; | ||
import PushNotification from '.'; | ||
import type {ReportActionPushNotificationData} from './NotificationType'; | ||
import type {PushNotificationData} from './NotificationType'; | ||
|
||
/** | ||
* Manage push notification subscriptions on sign-in/sign-out. | ||
|
@@ -33,6 +33,9 @@ Onyx.connect({ | |
|
||
PushNotification.onReceived(PushNotification.TYPE.REPORT_ACTION, applyOnyxData); | ||
PushNotification.onSelected(PushNotification.TYPE.REPORT_ACTION, navigateToReport); | ||
|
||
PushNotification.onReceived(PushNotification.TYPE.TRANSACTION, applyOnyxData); | ||
PushNotification.onSelected(PushNotification.TYPE.TRANSACTION, navigateToReport); | ||
} else { | ||
PushNotification.deregister(); | ||
PushNotification.clearNotifications(); | ||
|
@@ -62,8 +65,8 @@ Onyx.connect({ | |
}, | ||
}); | ||
|
||
function applyOnyxData({reportID, reportActionID, onyxData, lastUpdateID, previousUpdateID, hasPendingOnyxUpdates = false}: ReportActionPushNotificationData): Promise<void> { | ||
Log.info(`[PushNotification] Applying onyx data in the ${Visibility.isVisible() ? 'foreground' : 'background'}`, false, {reportID, reportActionID}); | ||
function applyOnyxData({reportID, onyxData, lastUpdateID, previousUpdateID, hasPendingOnyxUpdates = false}: PushNotificationData): Promise<void> { | ||
Log.info(`[PushNotification] Applying onyx data in the ${Visibility.isVisible() ? 'foreground' : 'background'}`, false, {reportID}); | ||
|
||
const logMissingOnyxDataInfo = (isDataMissing: boolean): boolean => { | ||
if (isDataMissing) { | ||
|
@@ -117,8 +120,8 @@ function applyOnyxData({reportID, reportActionID, onyxData, lastUpdateID, previo | |
return getLastUpdateIDAppliedToClient().then((lastUpdateIDAppliedToClient) => applyOnyxUpdatesReliably(updates, {shouldRunSync: true, clientLastUpdateID: lastUpdateIDAppliedToClient})); | ||
} | ||
|
||
function navigateToReport({reportID, reportActionID}: ReportActionPushNotificationData): Promise<void> { | ||
Log.info('[PushNotification] Navigating to report', false, {reportID, reportActionID}); | ||
function navigateToReport({reportID}: PushNotificationData): Promise<void> { | ||
Log.info('[PushNotification] Navigating to report', false, {reportID}); | ||
|
||
const policyID = lastVisitedPath && extractPolicyIDFromPath(lastVisitedPath); | ||
|
||
|
@@ -129,7 +132,7 @@ function navigateToReport({reportID, reportActionID}: ReportActionPushNotificati | |
// When transitioning to the new experience via the singleNewDotEntry flow, the navigation | ||
// is handled elsewhere. So we cancel here to prevent double navigation. | ||
if (isSingleNewDotEntry) { | ||
Log.info('[PushNotification] Not navigating because this is a singleNewDotEntry flow', false, {reportID, reportActionID}); | ||
Log.info('[PushNotification] Not navigating because this is a singleNewDotEntry flow', false, {reportID}); | ||
return; | ||
} | ||
|
||
|
@@ -142,7 +145,7 @@ function navigateToReport({reportID, reportActionID}: ReportActionPushNotificati | |
Navigation.goBack(); | ||
} | ||
|
||
Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID, reportActionID}); | ||
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. NAB: You're sure the reportActionID isn't useful in the logs? 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. Yeah since we're just navigating to the report, it's not really important here. |
||
Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID}); | ||
Navigation.navigateToReportWithPolicyCheck({reportID: String(reportID), policyIDToCheck: policyID}); | ||
updateLastVisitedPath(ROUTES.REPORT_WITH_ID.getRoute(String(reportID))); | ||
} catch (error) { | ||
|
@@ -151,7 +154,7 @@ function navigateToReport({reportID, reportActionID}: ReportActionPushNotificati | |
errorMessage = error.message; | ||
} | ||
|
||
Log.alert('[PushNotification] onSelected() - failed', {reportID, reportActionID, error: errorMessage}); | ||
Log.alert('[PushNotification] onSelected() - failed', {reportID, error: errorMessage}); | ||
} | ||
}); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: We don't have to refactor or fix this now but it's kind of weird that we do the same thing for all of these different types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'm working on removing the moneyRequest type since it's redundant. Handling transactions will also change a bit to handle some edge cases. I'm just handling the simple case for now though.