From afb2e6fd92fe9d00e3091770048a574e90061d1f Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 31 Oct 2018 15:40:39 -0300 Subject: [PATCH] Clear iOS notification on resume/open (#520) --- app/push/index.js | 7 ++++--- app/push/push.android.js | 2 ++ app/push/push.ios.js | 4 ++++ app/sagas/state.js | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/push/index.js b/app/push/index.js index 10ab113a0..c67f3d2de 100644 --- a/app/push/index.js +++ b/app/push/index.js @@ -31,12 +31,13 @@ const onNotification = (notification) => { } }; +const getDeviceToken = () => PushNotification.getDeviceToken(); +const setBadgeCount = count => PushNotification.setBadgeCount(count); const initializePushNotifications = () => { PushNotification.configure({ onNotification }); + setBadgeCount(); }; -const getDeviceToken = () => PushNotification.getDeviceToken(); - -export { initializePushNotifications, getDeviceToken }; +export { initializePushNotifications, getDeviceToken, setBadgeCount }; diff --git a/app/push/push.android.js b/app/push/push.android.js index 6e7ab0248..e34d70b26 100644 --- a/app/push/push.android.js +++ b/app/push/push.android.js @@ -19,6 +19,8 @@ class PushNotification { return this.deviceToken; } + setBadgeCount = () => {} + configure(params) { this.onRegister = params.onRegister; this.onNotification = params.onNotification; diff --git a/app/push/push.ios.js b/app/push/push.ios.js index 0636ea8c4..0c1415715 100644 --- a/app/push/push.ios.js +++ b/app/push/push.ios.js @@ -21,6 +21,10 @@ class PushNotification { return this.deviceToken; } + setBadgeCount = (count = 0) => { + NotificationsIOS.setBadgesCount(count); + } + configure(params) { this.onRegister = params.onRegister; this.onNotification = params.onNotification; diff --git a/app/sagas/state.js b/app/sagas/state.js index fbfb1f9de..20dc38d91 100644 --- a/app/sagas/state.js +++ b/app/sagas/state.js @@ -3,6 +3,7 @@ import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-ap import RocketChat from '../lib/rocketchat'; import log from '../utils/log'; +import { setBadgeCount } from '../push'; const appHasComeBackToForeground = function* appHasComeBackToForeground() { const appRoot = yield select(state => state.app.root); @@ -14,6 +15,7 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() { return; } try { + setBadgeCount(); return yield RocketChat.setUserPresenceOnline(); } catch (e) { log('appHasComeBackToForeground', e);