Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
ICU-687/ICU-688/ICU-689/ICU-690 Fixed channels staying in the UNREADS…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
hmhealey authored and enahum committed Feb 5, 2018
1 parent 4f7ad50 commit 427b0da
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 65 deletions.
7 changes: 1 addition & 6 deletions actions/global_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

Expand Down
16 changes: 0 additions & 16 deletions actions/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
4 changes: 0 additions & 4 deletions components/sidebar/sidebar_channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,8 +83,6 @@ function makeMapStateToProps() {
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
clearKeepChannelIdAsUnread,
keepChannelIdAsUnread,
savePreferences,
leaveChannel
}, dispatch)
Expand Down
13 changes: 1 addition & 12 deletions components/sidebar/sidebar_channel/sidebar_channel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
28 changes: 23 additions & 5 deletions reducers/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -38,14 +38,15 @@ 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;
return nextState;
}
return state;
}

default:
return state;
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions stores/channel_store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions utils/constants.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down

0 comments on commit 427b0da

Please sign in to comment.