MM-14630 Mark channel as read and viewed when opening brought from the background (#2658)

This commit is contained in:
Elias Nahum 2019-03-19 19:58:23 -03:00
parent ebe776e8b4
commit 96571c0f9c
No known key found for this signature in database
GPG key ID: E038DB71E0B61702
6 changed files with 20 additions and 13 deletions

View file

@ -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();

View file

@ -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,

View file

@ -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 {

View file

@ -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);
}
}
};

View file

@ -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),
};
}

View file

@ -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 {