diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index 428825307..f26a8acde 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -8,6 +8,7 @@ import {ViewTypes} from 'app/constants'; import {UserTypes} from 'mattermost-redux/action_types'; import { fetchMyChannelsAndMembers, + markChannelAsRead, selectChannel, leaveChannel as serviceLeaveChannel, unfavoriteChannel @@ -236,20 +237,27 @@ export function selectInitialChannel(teamId) { if (lastChannelId && myMembers[lastChannelId] && (lastChannel.team_id === teamId || isDMVisible || isGMVisible)) { handleSelectChannel(lastChannelId)(dispatch, getState); + markChannelAsRead(lastChannelId)(dispatch, getState); return; } const channel = Object.values(channels).find((c) => c.team_id === teamId && c.name === General.DEFAULT_CHANNEL); + let channelId; if (channel) { - dispatch(setChannelDisplayName('')); - handleSelectChannel(channel.id)(dispatch, getState); + channelId = channel.id; } else { // Handle case when the default channel cannot be found // so we need to get the first available channel of the team const channelsInTeam = Object.values(channels).filter((c) => c.team_id === teamId); const firstChannel = channelsInTeam.length ? channelsInTeam[0].id : {id: ''}; + + channelId = firstChannel.id; + } + + if (channelId) { dispatch(setChannelDisplayName('')); - handleSelectChannel(firstChannel.id)(dispatch, getState); + handleSelectChannel(channelId)(dispatch, getState); + markChannelAsRead(channelId)(dispatch, getState); } }; } diff --git a/app/actions/views/select_team.js b/app/actions/views/select_team.js index c0357bb5d..24685e2fe 100644 --- a/app/actions/views/select_team.js +++ b/app/actions/views/select_team.js @@ -28,9 +28,10 @@ export function handleTeamChange(teamId, selectChannel = true) { if (selectChannel) { actions.push({type: ChannelTypes.SELECT_CHANNEL, data: ''}); - const lastChannelId = state.views.team.lastChannelForTeam[teamId] || ''; + const lastChannels = state.views.team.lastChannelForTeam[teamId] || []; + const lastChannelId = lastChannels[0] || ''; const currentChannelId = getCurrentChannelId(state); - viewChannel(lastChannelId, currentChannelId)(dispatch, getState); + viewChannel(currentChannelId)(dispatch, getState); markChannelAsRead(lastChannelId, currentChannelId)(dispatch, getState); } diff --git a/app/push_notifications/push_notifications.ios.js b/app/push_notifications/push_notifications.ios.js index 7cea3c312..0c1a75195 100644 --- a/app/push_notifications/push_notifications.ios.js +++ b/app/push_notifications/push_notifications.ios.js @@ -8,6 +8,7 @@ const CATEGORY = 'CAN_REPLY'; const REPLY_ACTION = 'REPLY_ACTION'; let replyCategory; +const replies = new Set(); class PushNotification { constructor() { @@ -74,7 +75,8 @@ class PushNotification { const text = action.text; const badge = parseInt(action.notification._badge, 10) - 1; //eslint-disable-line no-underscore-dangle - if (this.onReply) { + if (this.onReply && !replies.has(action.completionKey)) { + replies.add(action.completionKey); this.onReply(data, text, badge, completed); } } else { diff --git a/app/screens/channel/channel.js b/app/screens/channel/channel.js index 3da4afc82..c3932f2be 100644 --- a/app/screens/channel/channel.js +++ b/app/screens/channel/channel.js @@ -64,14 +64,6 @@ class Channel extends PureComponent { } } - componentDidMount() { - // Mark current channel as read when opening app while logged in - if (this.props.currentChannelId) { - this.props.actions.markChannelAsRead(this.props.currentChannelId); - this.props.actions.viewChannel(this.props.currentChannelId); - } - } - componentWillReceiveProps(nextProps) { if (nextProps.currentTeamId && this.props.currentTeamId !== nextProps.currentTeamId) { this.loadChannels(nextProps.currentTeamId); diff --git a/app/selectors/post_list.js b/app/selectors/post_list.js index 2d2730a23..94e0187ff 100644 --- a/app/selectors/post_list.js +++ b/app/selectors/post_list.js @@ -25,9 +25,10 @@ export function makePreparePostIdsForPostList() { return createIdsSelector( (state, props) => getMyPosts(state, props.postIds), (state, props) => props.lastViewedAt, + (state, props) => props.indicateNewMessages, getCurrentUserId, shouldShowJoinLeaveMessages, - (posts, lastViewedAt, currentUserId, showJoinLeave) => { + (posts, lastViewedAt, indicateNewMessages, currentUserId, showJoinLeave) => { if (posts.length === 0) { return []; } @@ -62,8 +63,8 @@ export function makePreparePostIdsForPostList() { } // Only add the new messages line if a lastViewedAt time is set - const postIsUnread = post.create_at > lastViewedAt; - if (lastViewedAt != null && !addedNewMessagesIndicator && postIsUnread) { + const postIsUnread = post.create_at > lastViewedAt && post.user_id !== currentUserId; + if (lastViewedAt !== null && !addedNewMessagesIndicator && postIsUnread && indicateNewMessages) { out.push(START_OF_NEW_MESSAGES); addedNewMessagesIndicator = true; }