Commit 427b0da9 authored by Harrison Healey's avatar Harrison Healey Committed by enahum

ICU-687/ICU-688/ICU-689/ICU-690 Fixed channels staying in the UNREADS section after viewing (#705)

* ICU-687/ICU-688/ICU-689/ICU-690 Fixed channels staying in the UNREADS section after viewing

* Updates snapshots

* Removed unused redux actions

* Reverted return statement for empty SidebarChannel
parent 4f7ad50c
......@@ -44,7 +44,6 @@ export function emitChannelClickEvent(channel) {
}
}
function switchToChannel(chan) {
const channelMember = ChannelStore.getMyMember(chan.id);
const getMyChannelMemberPromise = getMyChannelMember(chan.id)(dispatch, getState);
const oldChannelId = ChannelStore.getCurrentId();
......@@ -63,12 +62,8 @@ export function emitChannelClickEvent(channel) {
AppDispatcher.handleViewAction({
type: ActionTypes.CLICK_CHANNEL,
name: chan.name,
id: chan.id,
team_id: chan.team_id,
total_msg_count: chan.total_msg_count,
channelMember,
prev: oldChannelId
team_id: chan.team_id
});
}
......
......@@ -12,19 +12,3 @@ export function checkAndSetMobileView() {
});
};
}
export function keepChannelIdAsUnread(channelId, hadMentions) {
return {
type: ActionTypes.KEEP_CHANNEL_AS_UNREAD,
data: {
id: channelId,
hadMentions
}
};
}
export function clearKeepChannelIdAsUnread() {
return {
type: ActionTypes.CLEAR_KEEP_CHANNEL_AS_UNREAD
};
}
......@@ -11,8 +11,6 @@ import {savePreferences} from 'mattermost-redux/actions/preferences';
import {leaveChannel} from 'mattermost-redux/actions/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {clearKeepChannelIdAsUnread, keepChannelIdAsUnread} from 'actions/views/channel';
import {Constants, NotificationLevels} from 'utils/constants.jsx';
import SidebarChannel from './sidebar_channel.jsx';
......@@ -85,8 +83,6 @@ function makeMapStateToProps() {
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
clearKeepChannelIdAsUnread,
keepChannelIdAsUnread,
savePreferences,
leaveChannel
}, dispatch)
......
......@@ -122,8 +122,6 @@ export default class SidebarChannel extends React.PureComponent {
membersCount: PropTypes.number.isRequired,
actions: PropTypes.shape({
clearKeepChannelIdAsUnread: PropTypes.func.isRequired,
keepChannelIdAsUnread: PropTypes.func.isRequired,
savePreferences: PropTypes.func.isRequired,
leaveChannel: PropTypes.func.isRequired
}).isRequired
......@@ -179,21 +177,13 @@ export default class SidebarChannel extends React.PureComponent {
}
}
handleSelectChannel = () => {
if (this.showChannelAsUnread()) {
this.props.actions.keepChannelIdAsUnread(this.props.channelId, this.props.unreadMentions > 0);
} else {
this.props.actions.clearKeepChannelIdAsUnread(null, false);
}
};
showChannelAsUnread = () => {
return this.props.unreadMentions > 0 || (this.props.unreadMsgs > 0 && this.props.showUnreadForMsgs);
};
render = () => {
if (!this.props.channelDisplayName || !this.props.channelType) {
return null;
return (<div/>);
}
let closeHandler = null;
......@@ -284,7 +274,6 @@ export default class SidebarChannel extends React.PureComponent {
membersCount={this.props.membersCount}
teammateId={this.props.channelTeammateId}
teammateDeletedAt={this.props.channelTeammateDeletedAt}
onSelectChannel={this.handleSelectChannel}
/>
{tutorialTip}
</li>
......
......@@ -29,12 +29,10 @@ export default class SidebarChannelButtonOrLink extends React.PureComponent {
membersCount: PropTypes.number.isRequired,
unreadMentions: PropTypes.number,
teammateId: PropTypes.string,
teammateDeletedAt: PropTypes.number,
onSelectChannel: PropTypes.func.isRequired
teammateDeletedAt: PropTypes.number
}
trackChannelSelectedEvent = () => {
this.props.onSelectChannel();
mark('SidebarChannelLink#click');
trackEvent('ui', 'ui_channel_selected');
}
......
......@@ -4,7 +4,7 @@
import {combineReducers} from 'redux';
import {ChannelTypes, PostTypes, UserTypes} from 'mattermost-redux/action_types';
import {ActionTypes, Constants} from 'utils/constants.jsx';
import {ActionTypes, Constants, NotificationLevels} from 'utils/constants.jsx';
function postVisibility(state = {}, action) {
switch (action.type) {
......@@ -38,7 +38,7 @@ function postVisibility(state = {}, action) {
function lastChannelViewTime(state = {}, action) {
switch (action.type) {
case ChannelTypes.SELECT_CHANNEL: {
case ActionTypes.SELECT_CHANNEL_WITH_MEMBER: {
if (action.member) {
const nextState = {...state};
nextState[action.data] = action.member.last_viewed_at;
......@@ -46,6 +46,7 @@ function lastChannelViewTime(state = {}, action) {
}
return state;
}
default:
return state;
}
......@@ -85,10 +86,27 @@ function mobileView(state = false, action) {
function keepChannelIdAsUnread(state = null, action) {
switch (action.type) {
case ActionTypes.KEEP_CHANNEL_AS_UNREAD:
return action.data;
case ActionTypes.CLEAR_KEEP_CHANNEL_AS_UNREAD:
case ActionTypes.SELECT_CHANNEL_WITH_MEMBER: {
const member = action.member;
const channel = action.channel;
if (!member || !channel) {
return state;
}
const msgCount = channel.total_msg_count - member.msg_count;
const showChannelAsUnread = member.mentionCount > 0 ||
(member.notify_props.mark_unread !== NotificationLevels.MENTION && msgCount > 0);
if (showChannelAsUnread) {
return {
id: member.channel_id,
hadMentions: member.mentionCount > 0
};
}
return null;
}
case UserTypes.LOGOUT_SUCCESS:
return null;
......
......@@ -163,11 +163,15 @@ class ChannelStoreClass extends EventEmitter {
}
setCurrentId(id) {
store.dispatch({
store.dispatch(batchActions([{
type: ChannelTypes.SELECT_CHANNEL,
data: id
}, {
type: ActionTypes.SELECT_CHANNEL_WITH_MEMBER,
data: id,
channel: this.getChannelById(id),
member: this.getMyMember(id)
});
}]));
}
resetCounts(ids) {
......
......@@ -14,7 +14,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/messages/@undefined"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -37,7 +36,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/messages/@undefined"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -60,7 +58,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={null}
link="/current-team/channels/town-square"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -87,7 +84,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/messages/@undefined"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item unread-title has-badge"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -110,7 +106,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/messages/@undefined"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -133,7 +128,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={null}
link="/current-team/channels/town-square"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -156,7 +150,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={null}
link="/current-team/channels/town-square"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -179,7 +172,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/channels/channel-name?fakechannel=%7B%22display_name%22%3A%22Channel%20display%20name%22%2C%22name%22%3A%22channel-name%22%2C%22type%22%3A%22D%22%2C%22id%22%3A%22test-channel-id%22%2C%22status%22%3A%22test%22%2C%22fake%22%3Atrue%7D"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -202,7 +194,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={null}
link="/current-team/channels/channel-name"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -225,7 +216,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/channels/channel-name"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -258,7 +248,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/messages/@undefined"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="myself"
......@@ -281,7 +270,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={null}
link="/current-team/channels/channel-name"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -304,7 +292,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/channels/channel-name"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -327,7 +314,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={null}
link="/current-team/channels/channel-name"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item"
teammateDeletedAt={1}
teammateId="teammate-id"
......@@ -350,7 +336,6 @@ exports[`component/sidebar/sidebar_channel/SidebarChannel should match snapshot,
handleClose={[Function]}
link="/current-team/channels/channel-name"
membersCount={8}
onSelectChannel={[Function]}
rowClass="sidebar-item has-close"
teammateDeletedAt={1}
teammateId="teammate-id"
......
......@@ -238,8 +238,7 @@ export const ActionTypes = keyMirror({
POPOVER_MENTION_KEY_CLICK: null,
KEEP_CHANNEL_AS_UNREAD: null,
CLEAR_KEEP_CHANNEL_AS_UNREAD: null,
SELECT_CHANNEL_WITH_MEMBER: null,
INCREMENT_EMOJI_PICKER_PAGE: null
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment