From 91f9ea572b8933b21a66d3c99b3db15eebd8758e Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 6 Dec 2018 13:11:31 -0300 Subject: [PATCH] Wait 1s before clearing notifications when app is brought to the foreground (#2419) --- .../network_indicator/network_indicator.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/components/network_indicator/network_indicator.js b/app/components/network_indicator/network_indicator.js index b7bf177b5..41f6dbef5 100644 --- a/app/components/network_indicator/network_indicator.js +++ b/app/components/network_indicator/network_indicator.js @@ -70,6 +70,7 @@ export default class NetworkIndicator extends PureComponent { const navBar = this.getNavBarHeight(props.isLandscape); this.top = new Animated.Value(navBar - HEIGHT); this.opacity = 0; + this.clearNotificationTimeout = null; this.backgroundColor = new Animated.Value(0); this.firstRun = true; @@ -88,8 +89,17 @@ export default class NetworkIndicator extends PureComponent { } componentDidUpdate(prevProps) { - const {isLandscape: prevIsLandscape, websocketStatus: previousWebsocketStatus} = prevProps; - const {isLandscape, websocketErrorCount, websocketStatus} = this.props; + const { + currentChannelId: prevChannelId, + isLandscape: prevIsLandscape, + websocketStatus: previousWebsocketStatus, + } = prevProps; + const {currentChannelId, isLandscape, websocketErrorCount, websocketStatus} = this.props; + + if (currentChannelId !== prevChannelId && this.clearNotificationTimeout) { + clearTimeout(this.clearNotificationTimeout); + this.clearNotificationTimeout = null; + } if (isLandscape !== prevIsLandscape) { const navBar = this.getNavBarHeight(isLandscape); @@ -220,7 +230,12 @@ export default class NetworkIndicator extends PureComponent { this.connect(true); if (currentChannelId) { - PushNotifications.clearChannelNotifications(currentChannelId); + // Clear the notifications for the current channel after one second + // this is done so we can cancel it in case the app is brought to the + // foreground by tapping a notification from another channel + this.clearNotificationTimeout = setTimeout(() => { + PushNotifications.clearChannelNotifications(currentChannelId); + }, 1000); } } else { this.handleWebSocket(false);