[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:
parent
20c981a35d
commit
bad7b85d40
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue