From 96571c0f9c3234f804a48e147ce3058b4ecda1ba Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 19 Mar 2019 19:58:23 -0300 Subject: [PATCH] MM-14630 Mark channel as read and viewed when opening brought from the background (#2658) --- app/actions/views/channel.js | 10 ++++++++-- app/components/network_indicator/index.js | 2 ++ app/components/network_indicator/network_indicator.js | 4 +++- app/screens/channel_peek/channel_peek.js | 4 ++-- app/screens/channel_peek/index.js | 5 ++--- app/utils/push_notifications.js | 8 +++----- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index f4682dd84..8065f4e2d 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -385,8 +385,7 @@ export function handleSelectChannel(channelId, fromPushNotification = false) { markPreviousChannelId = currentChannelId; } - dispatch(markChannelAsRead(channelId, markPreviousChannelId)); - dispatch(markChannelAsViewed(channelId, markPreviousChannelId)); + dispatch(markChannelViewedAndRead(channelId, markPreviousChannelId)); }; } @@ -411,6 +410,13 @@ export function insertToDraft(value) { }; } +export function markChannelViewedAndRead(channelId, previousChannelId, markOnServer = true) { + return (dispatch) => { + dispatch(markChannelAsRead(channelId, previousChannelId, markOnServer)); + dispatch(markChannelAsViewed(channelId, previousChannelId)); + }; +} + export function toggleDMChannel(otherUserId, visible, channelId) { return async (dispatch, getState) => { const state = getState(); diff --git a/app/components/network_indicator/index.js b/app/components/network_indicator/index.js index 7075f8ff3..665261c51 100644 --- a/app/components/network_indicator/index.js +++ b/app/components/network_indicator/index.js @@ -9,6 +9,7 @@ import {init as initWebSocket, close as closeWebSocket} from 'mattermost-redux/a import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; import {connection} from 'app/actions/device'; +import {markChannelViewedAndRead} from 'app/actions/views/channel'; import {setCurrentUserStatusOffline} from 'app/actions/views/user'; import {getConnection, isLandscape} from 'app/selectors/device'; @@ -34,6 +35,7 @@ function mapDispatchToProps(dispatch) { connection, initWebSocket, logout, + markChannelViewedAndRead, setCurrentUserStatusOffline, startPeriodicStatusUpdates, stopPeriodicStatusUpdates, diff --git a/app/components/network_indicator/network_indicator.js b/app/components/network_indicator/network_indicator.js index 1c89987f7..56e4b9f65 100644 --- a/app/components/network_indicator/network_indicator.js +++ b/app/components/network_indicator/network_indicator.js @@ -43,6 +43,7 @@ export default class NetworkIndicator extends PureComponent { closeWebSocket: PropTypes.func.isRequired, connection: PropTypes.func.isRequired, initWebSocket: PropTypes.func.isRequired, + markChannelViewedAndRead: PropTypes.func.isRequired, logout: PropTypes.func.isRequired, setCurrentUserStatusOffline: PropTypes.func.isRequired, startPeriodicStatusUpdates: PropTypes.func.isRequired, @@ -226,7 +227,7 @@ export default class NetworkIndicator extends PureComponent { }; handleAppStateChange = async (appState) => { - const {currentChannelId} = this.props; + const {actions, currentChannelId} = this.props; const active = appState === 'active'; if (active) { @@ -238,6 +239,7 @@ export default class NetworkIndicator extends PureComponent { // foreground by tapping a notification from another channel this.clearNotificationTimeout = setTimeout(() => { PushNotifications.clearChannelNotifications(currentChannelId); + actions.markChannelViewedAndRead(currentChannelId); }, 1000); } } else { diff --git a/app/screens/channel_peek/channel_peek.js b/app/screens/channel_peek/channel_peek.js index ce732cf20..bd8734848 100644 --- a/app/screens/channel_peek/channel_peek.js +++ b/app/screens/channel_peek/channel_peek.js @@ -12,7 +12,7 @@ export default class ChannelPeek extends PureComponent { static propTypes = { actions: PropTypes.shape({ loadPostsIfNecessaryWithRetry: PropTypes.func.isRequired, - markChannelAsRead: PropTypes.func.isRequired, + markChannelViewedAndRead: PropTypes.func.isRequired, }).isRequired, channelId: PropTypes.string.isRequired, currentUserId: PropTypes.string, @@ -59,7 +59,7 @@ export default class ChannelPeek extends PureComponent { if (event.type === 'PreviewActionPress') { if (event.id === 'action-mark-as-read') { const {actions, channelId} = this.props; - actions.markChannelAsRead(channelId); + actions.markChannelViewedAndRead(channelId); } } }; diff --git a/app/screens/channel_peek/index.js b/app/screens/channel_peek/index.js index 87bf323fd..415f1c0bd 100644 --- a/app/screens/channel_peek/index.js +++ b/app/screens/channel_peek/index.js @@ -4,11 +4,10 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {markChannelAsRead} from 'mattermost-redux/actions/channels'; import {getPostIdsInChannel} from 'mattermost-redux/selectors/entities/posts'; import {getMyChannelMember} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import {loadPostsIfNecessaryWithRetry} from 'app/actions/views/channel'; +import {loadPostsIfNecessaryWithRetry, markChannelViewedAndRead} from 'app/actions/views/channel'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import ChannelPeek from './channel_peek'; @@ -30,7 +29,7 @@ function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ loadPostsIfNecessaryWithRetry, - markChannelAsRead, + markChannelViewedAndRead, }, dispatch), }; } diff --git a/app/utils/push_notifications.js b/app/utils/push_notifications.js index 70553d4b0..a26781e90 100644 --- a/app/utils/push_notifications.js +++ b/app/utils/push_notifications.js @@ -4,7 +4,6 @@ import {Platform} from 'react-native'; import DeviceInfo from 'react-native-device-info'; -import {markChannelAsRead, markChannelAsViewed} from 'mattermost-redux/actions/channels'; import {setDeviceToken} from 'mattermost-redux/actions/general'; import {getPosts} from 'mattermost-redux/actions/posts'; import {Client4} from 'mattermost-redux/client'; @@ -12,7 +11,7 @@ import {General} from 'mattermost-redux/constants'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; -import {retryGetPostsAction} from 'app/actions/views/channel'; +import {markChannelViewedAndRead, retryGetPostsAction} from 'app/actions/views/channel'; import { createPostForNotificationReply, loadFromPushNotification, @@ -78,8 +77,7 @@ const onPushNotification = async (deviceNotification) => { } if (data.type === 'clear') { - dispatch(markChannelAsRead(data.channel_id, null, false)); - dispatch(markChannelAsViewed(data.channel_id, null)); + dispatch(markChannelViewedAndRead(data.channel_id, null, false)); } else { // get the posts for the channel as soon as possible retryGetPostsAction(getPosts(data.channel_id), dispatch, getState); @@ -159,7 +157,7 @@ export const onPushNotificationReply = async (data, text, badge, completed) => { PushNotifications.setApplicationIconBadgeNumber(badge); } - dispatch(markChannelAsRead(data.channel_id)); + dispatch(markChannelViewedAndRead(data.channel_id)); app.setReplyNotificationData(null); completed(); } else {