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

Commit

Permalink
ICU-686 Fixed channels ignoring mark unread setting (#700)
Browse files Browse the repository at this point in the history
* ICU-686 Fixed channels ignoring mark unread setting

* Updated snapshots

* Fixed channel leave/close styling in sidebar

* Updated snapshots again
  • Loading branch information
hmhealey authored Feb 5, 2018
1 parent 0c1a44a commit 0ee6b73
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 389 deletions.
23 changes: 11 additions & 12 deletions actions/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ export function checkAndSetMobileView() {
};
}

export function keepChanneIdAsUnread(channelId, hadMentions = false) {
return (dispatch) => {
let data = null;
if (channelId) {
data = {
id: channelId,
hadMentions
};
export function keepChannelIdAsUnread(channelId, hadMentions) {
return {
type: ActionTypes.KEEP_CHANNEL_AS_UNREAD,
data: {
id: channelId,
hadMentions
}
};
}

dispatch({
type: ActionTypes.KEEP_CHANNEL_AS_UNREAD,
data
});
export function clearKeepChannelIdAsUnread() {
return {
type: ActionTypes.CLEAR_KEEP_CHANNEL_AS_UNREAD
};
}
2 changes: 0 additions & 2 deletions components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
getSortedFavoriteChannelWithUnreadsIds,
getSortedDirectChannelWithUnreadsIds,
getCurrentChannel,
getMyChannelMemberships,
getUnreads,
getSortedUnreadChannelIds,
getSortedDirectChannelIds,
Expand Down Expand Up @@ -69,7 +68,6 @@ function mapStateToProps(state) {
currentTeammate,
currentTeam: getCurrentTeam(state),
currentUser: getCurrentUser(state),
memberships: getMyChannelMemberships(state),
unreads: getUnreads(state),
isSystemAdmin: isCurrentUserSystemAdmin(state),
isTeamAdmin: isCurrentUserCurrentTeamAdmin(state)
Expand Down
14 changes: 4 additions & 10 deletions components/sidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ export default class Sidebar extends React.PureComponent {
*/
currentUser: PropTypes.object.isRequired,

/**
* User channels memerships
*/
memberships: PropTypes.object.isRequired,

/**
* Number of unread mentions/messages
*/
Expand Down Expand Up @@ -412,10 +407,10 @@ export default class Sidebar extends React.PureComponent {

getDisplayedChannels = (props = this.props) => {
return props.unreadChannelIds.
concat(props.favoriteChannelIds).
concat(props.publicChannelIds).
concat(props.privateChannelIds).
concat(props.directAndGroupChannelIds);
concat(props.favoriteChannelIds).
concat(props.publicChannelIds).
concat(props.privateChannelIds).
concat(props.directAndGroupChannelIds);
};

channelIdIsDisplayedForProps = (props, id) => {
Expand Down Expand Up @@ -467,7 +462,6 @@ export default class Sidebar extends React.PureComponent {
key={channelId}
ref={channelId}
channelId={channelId}
membership={this.props.memberships[channelId]}
active={channelId === this.props.currentChannel.id}
currentTeamName={this.props.currentTeam.name}
currentUserId={this.props.currentUser.id}
Expand Down
35 changes: 24 additions & 11 deletions components/sidebar/sidebar_channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';

import {getChannelsNameMapInCurrentTeam, makeGetChannel} from 'mattermost-redux/selectors/entities/channels';
import {getChannelsNameMapInCurrentTeam, getMyChannelMemberships, makeGetChannel} from 'mattermost-redux/selectors/entities/channels';
import {getUserIdsInChannels, getUser} from 'mattermost-redux/selectors/entities/users';
import {get as getPreference} from 'mattermost-redux/selectors/entities/preferences';
import {savePreferences} from 'mattermost-redux/actions/preferences';
import {leaveChannel} from 'mattermost-redux/actions/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';

import {keepChanneIdAsUnread} from 'actions/views/channel';
import {clearKeepChannelIdAsUnread, keepChannelIdAsUnread} from 'actions/views/channel';

import {Constants} from 'utils/constants.jsx';
import {Constants, NotificationLevels} from 'utils/constants.jsx';

import SidebarChannel from './sidebar_channel.jsx';

function makeMapStateToProps() {
const getChannel = makeGetChannel();

return (state, ownProps) => {
const channelId = ownProps.channelId;

const config = getConfig(state);
const channel = getChannel(state, {id: ownProps.channelId}) || {};
const channel = getChannel(state, {id: channelId}) || {};
const tutorialStep = getPreference(state, Constants.Preferences.TUTORIAL_STEP, ownProps.currentUserId, 999);
const channelsByName = getChannelsNameMapInCurrentTeam(state);
const memberIds = getUserIdsInChannels(state);
Expand All @@ -35,12 +37,21 @@ function makeMapStateToProps() {
}
}

const member = ownProps.membership;
const unreadMentions = member ? member.mention_count : 0;
const member = getMyChannelMemberships(state)[channelId];

let unreadMentions = 0;
let unreadMsgs = 0;
let showUnreadForMsgs = true;
if (member) {
unreadMentions = member.mention_count;

let unreadMsgs = channel && member ? channel.total_msg_count - member.msg_count : 0;
if (unreadMsgs < 0) {
unreadMsgs = 0;
if (channel) {
unreadMsgs = Math.max(channel.total_msg_count - member.msg_count, 0);
}

if (member.notify_props) {
showUnreadForMsgs = member.notify_props.mark_unread !== NotificationLevels.MENTION;
}
}

let teammate = null;
Expand All @@ -50,7 +61,7 @@ function makeMapStateToProps() {

return {
config,
channelId: channel.id,
channelId,
channelName: channel.name,
channelDisplayName: channel.display_name,
channelType: channel.type,
Expand All @@ -63,6 +74,7 @@ function makeMapStateToProps() {
showTutorialTip: tutorialStep === Constants.TutorialSteps.CHANNEL_POPOVER && config.EnableTutorial === 'true',
townSquareDisplayName: channelsByName[Constants.DEFAULT_CHANNEL] && channelsByName[Constants.DEFAULT_CHANNEL].display_name,
offTopicDisplayName: channelsByName[Constants.OFFTOPIC_CHANNEL] && channelsByName[Constants.OFFTOPIC_CHANNEL].display_name,
showUnreadForMsgs,
unreadMsgs,
unreadMentions,
membersCount
Expand All @@ -73,7 +85,8 @@ function makeMapStateToProps() {
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
keepChanneIdAsUnread,
clearKeepChannelIdAsUnread,
keepChannelIdAsUnread,
savePreferences,
leaveChannel
}, dispatch)
Expand Down
43 changes: 19 additions & 24 deletions components/sidebar/sidebar_channel/sidebar_channel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export default class SidebarChannel extends React.PureComponent {
channelTeammateDeletedAt: PropTypes.number,

/**
* User's channel membership
* Whether or not to mark the channel as unread when it has unread messages and no mentions
*/
membership: PropTypes.object,
showUnreadForMsgs: PropTypes.bool.isRequired,

/**
* Number of unread messages
Expand Down Expand Up @@ -122,7 +122,8 @@ export default class SidebarChannel extends React.PureComponent {
membersCount: PropTypes.number.isRequired,

actions: PropTypes.shape({
keepChanneIdAsUnread: PropTypes.func.isRequired,
clearKeepChannelIdAsUnread: PropTypes.func.isRequired,
keepChannelIdAsUnread: PropTypes.func.isRequired,
savePreferences: PropTypes.func.isRequired,
leaveChannel: PropTypes.func.isRequired
}).isRequired
Expand Down Expand Up @@ -179,25 +180,22 @@ export default class SidebarChannel extends React.PureComponent {
}

handleSelectChannel = () => {
const {actions, channelId} = this.props;
actions.keepChanneIdAsUnread(this.isChannelUnread() ? channelId : null, this.props.unreadMentions > 0);
};

isChannelUnread = () => {
const {membership, unreadMsgs, unreadMentions} = this.props;

if (membership) {
const msgCount = unreadMsgs + unreadMentions;
return msgCount > 0 || membership.mention_count > 0;
if (this.showChannelAsUnread()) {
this.props.actions.keepChannelIdAsUnread(this.props.channelId, this.props.unreadMentions > 0);
} else {
this.props.actions.clearKeepChannelIdAsUnread(null, false);
}
};

return false;
showChannelAsUnread = () => {
return this.props.unreadMentions > 0 || (this.props.unreadMsgs > 0 && this.props.showUnreadForMsgs);
};

render = () => {
if (!this.props.channelDisplayName || !this.props.channelType) {
return (<div/>);
return null;
}

let closeHandler = null;
if (this.props.channelType === Constants.DM_CHANNEL || this.props.channelType === Constants.GM_CHANNEL) {
closeHandler = this.handleLeaveDirectChannel;
Expand All @@ -215,18 +213,15 @@ export default class SidebarChannel extends React.PureComponent {
}

let rowClass = 'sidebar-item';

if (this.isChannelUnread()) {
let badge = false;
if (this.showChannelAsUnread()) {
rowClass += ' unread-title';
}

var badge = false;
if (this.props.membership && this.props.unreadMentions) {
badge = true;
}
if (this.props.unreadMentions > 0) {
rowClass += ' has-badge';

if (this.props.unreadMentions > 0) {
rowClass += ' has-badge';
badge = true;
}
}

if (closeHandler && !badge) {
Expand Down
7 changes: 6 additions & 1 deletion reducers/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See License.txt for license information.

import {combineReducers} from 'redux';
import {ChannelTypes, PostTypes} from 'mattermost-redux/action_types';
import {ChannelTypes, PostTypes, UserTypes} from 'mattermost-redux/action_types';

import {ActionTypes, Constants} from 'utils/constants.jsx';

Expand Down Expand Up @@ -87,6 +87,11 @@ function keepChannelIdAsUnread(state = null, action) {
switch (action.type) {
case ActionTypes.KEEP_CHANNEL_AS_UNREAD:
return action.data;
case ActionTypes.CLEAR_KEEP_CHANNEL_AS_UNREAD:
return null;

case UserTypes.LOGOUT_SUCCESS:
return null;
default:
return state;
}
Expand Down
Loading

0 comments on commit 0ee6b73

Please sign in to comment.