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

Fix: prevent receiving notification when logging out #26973

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Airship from '@ua/react-native-airship';
import shouldShowPushNotification from '../shouldShowPushNotification';

function configureForegroundNotifications() {
Airship.push.android.setForegroundDisplayPredicate((pushPayload) => Promise.resolve(shouldShowPushNotification(pushPayload)));
}

function disableForegroundNotifications() {
Airship.push.android.setForegroundDisplayPredicate(() => Promise.resolve(false));
}

export default {
configureForegroundNotifications,
disableForegroundNotifications,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Airship, {iOS} from '@ua/react-native-airship';
import shouldShowPushNotification from '../shouldShowPushNotification';

export default function configureForegroundNotifications() {
function configureForegroundNotifications() {
// Set our default iOS foreground presentation to be loud with a banner
// More info here https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649518-usernotificationcenter
Airship.push.iOS.setForegroundPresentationOptions([
Expand All @@ -15,3 +15,12 @@ export default function configureForegroundNotifications() {
// Returning null keeps the default presentation. Returning [] uses no presentation (hides the notification).
Airship.push.iOS.setForegroundPresentationOptionsCallback((pushPayload) => Promise.resolve(shouldShowPushNotification(pushPayload) ? null : []));
}

function disableForegroundNotifications() {
Airship.push.iOS.setForegroundPresentationOptionsCallback(() => Promise.resolve([]));
}

export default {
configureForegroundNotifications,
disableForegroundNotifications,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/**
* Configures notification handling while in the foreground on iOS and Android. This is a no-op on other platforms.
*/
export default function () {}
export default {
configureForegroundNotifications: () => {},
disableForegroundNotifications: () => {},
};

This file was deleted.

5 changes: 3 additions & 2 deletions src/libs/Notification/PushNotification/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Log from '../../Log';
import NotificationType from './NotificationType';
import * as PushNotification from '../../actions/PushNotification';
import ONYXKEYS from '../../../ONYXKEYS';
import configureForegroundNotifications from './configureForegroundNotifications';
import ForegroundNotifications from './ForegroundNotifications';

let isUserOptedInToPushNotifications = false;
Onyx.connect({
Expand Down Expand Up @@ -96,7 +96,7 @@ function init() {
// Keep track of which users have enabled push notifications via an NVP.
Airship.addListener(EventType.NotificationOptInStatus, refreshNotificationOptInStatus);

configureForegroundNotifications();
ForegroundNotifications.configureForegroundNotifications();
}

/**
Expand Down Expand Up @@ -136,6 +136,7 @@ function deregister() {
Airship.contact.reset();
Airship.removeAllListeners(EventType.PushReceived);
Airship.removeAllListeners(EventType.NotificationResponse);
ForegroundNotifications.disableForegroundNotifications();
}

/**
Expand Down
Loading