[FIX] Disappear push notifications when open the app (#4718)

* [FIX] Disappear push notifications when open the app

* minor tweak

* test badgeCount

* refactor remove notification to remove notification and badge
This commit is contained in:
Reinaldo Neto 2022-12-21 13:07:17 -03:00 committed by Diego Mello
parent 20c981a35d
commit bad7b85d40
4 changed files with 11 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import EJSON from 'ejson';
import { store } from '../store/auxStore';
import { deepLinkingOpen } from '../../actions/deepLinking';
import { isFDroidBuild } from '../constants';
import { deviceToken, pushNotificationConfigure, setNotificationsBadgeCount } from './push';
import { deviceToken, pushNotificationConfigure, setNotificationsBadgeCount, removeAllNotifications } from './push';
import { INotification, SubscriptionType } from '../../definitions';
interface IEjson {
@ -49,6 +49,10 @@ export const onNotification = (push: INotification): void => {
export const getDeviceToken = (): string => deviceToken;
export const setBadgeCount = (count?: number): void => setNotificationsBadgeCount(count);
export const removeNotificationsAndBadge = () => {
removeAllNotifications();
setBadgeCount();
};
export const initializePushNotifications = (): Promise<INotification> | undefined => {
if (!isFDroidBuild) {
setBadgeCount();

View File

@ -21,6 +21,10 @@ export const setNotificationsBadgeCount = (count = 0): void => {
}
};
export const removeAllNotifications = (): void => {
Notifications.removeAllDeliveredNotifications();
};
export const pushNotificationConfigure = (onNotification: (notification: INotification) => void): Promise<any> => {
if (isIOS) {
// init

View File

@ -1,6 +1,7 @@
// https://github.com/bamlab/redux-enhancer-react-native-appstate
import { AppState } from 'react-native';
import { removeNotificationsAndBadge } from '../notifications';
import { APP_STATE } from '../../actions/actionsTypes';
export default () =>
@ -16,6 +17,7 @@ export default () =>
let type;
if (nextAppState === 'active') {
type = APP_STATE.FOREGROUND;
removeNotificationsAndBadge();
} else if (nextAppState === 'background') {
type = APP_STATE.BACKGROUND;
}

View File

@ -5,7 +5,6 @@ import { localAuthenticate, saveLastLocalAuthenticationSession } from '../lib/me
import { APP_STATE } from '../actions/actionsTypes';
import { RootEnum } from '../definitions';
import { Services } from '../lib/services';
import { setBadgeCount } from '../lib/notifications';
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
const appRoot = yield select(state => state.app.root);
@ -20,7 +19,6 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() {
try {
yield localAuthenticate(server.server);
Services.checkAndReopen();
setBadgeCount();
return yield Services.setUserPresenceOnline();
} catch (e) {
log(e);