Mark initial channel as read

This commit is contained in:
Elias Nahum 2017-11-13 21:05:27 -03:00 committed by enahum
parent 36d2087660
commit 240e52da6b
5 changed files with 21 additions and 17 deletions

View file

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

View file

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

View file

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

View file

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

View file

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