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

View File

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

View File

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