Skip to content

Commit

Permalink
Showing properly guest badge on channel group message header with ful…
Browse files Browse the repository at this point in the history
…l name (mattermost#3832)
  • Loading branch information
jespino committed Oct 2, 2019
1 parent facb5f4 commit f8cf9c5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
14 changes: 9 additions & 5 deletions components/channel_header/channel_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class ChannelHeader extends React.PureComponent {
channel: PropTypes.object,
channelMember: PropTypes.object,
dmUser: PropTypes.object,
gmMembers: PropTypes.array,
isFavorite: PropTypes.bool,
isReadOnly: PropTypes.bool,
isMuted: PropTypes.bool,
Expand Down Expand Up @@ -256,6 +257,7 @@ export default class ChannelHeader extends React.PureComponent {
const {
teamId,
currentUser,
gmMembers,
channel,
channelMember,
isMuted: channelMuted,
Expand Down Expand Up @@ -327,14 +329,16 @@ export default class ChannelHeader extends React.PureComponent {
}

if (isGroup) {
const usernames = channel.display_name.split(',');
const nodes = [];
for (const username of usernames) {
const user = Utils.getUserByUsername(username.trim());
for (const user of gmMembers) {
if (user.id === currentUser.id) {
continue;
}
const userDisplayName = Utils.getDisplayNameByUserId(user.id);
nodes.push((
<React.Fragment key={username}>
<React.Fragment key={userDisplayName}>
{nodes.length !== 0 && ', '}
{username}
{userDisplayName}
<GuestBadge show={Utils.isGuest(user)}/>
</React.Fragment>
));
Expand Down
55 changes: 32 additions & 23 deletions components/channel_header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {
getCurrentUser,
getUser,
makeGetProfilesInChannel,
} from 'mattermost-redux/selectors/entities/users';
import {getUserIdFromChannelName} from 'mattermost-redux/utils/channel_utils';

Expand All @@ -41,31 +42,39 @@ import {ModalIdentifiers} from 'utils/constants';

import ChannelHeader from './channel_header';

const mapStateToProps = (state) => {
const channel = getCurrentChannel(state) || {};
const user = getCurrentUser(state);
function makeMapStateToProps() {
const doGetProfilesInChannel = makeGetProfilesInChannel();

let dmUser;
if (channel && channel.type === General.DM_CHANNEL) {
const dmUserId = getUserIdFromChannelName(user.id, channel.name);
dmUser = getUser(state, dmUserId);
}
const stats = getCurrentChannelStats(state) || {member_count: 0, guest_count: 0};
return function mapStateToProps(state) {
const channel = getCurrentChannel(state) || {};
const user = getCurrentUser(state);

return {
teamId: getCurrentTeamId(state),
channel,
channelMember: getMyCurrentChannelMembership(state),
currentUser: user,
dmUser,
rhsState: getRhsState(state),
isFavorite: isCurrentChannelFavorite(state),
isReadOnly: isCurrentChannelReadOnly(state),
isMuted: isCurrentChannelMuted(state),
isQuickSwitcherOpen: isModalOpen(state, ModalIdentifiers.QUICK_SWITCH),
hasGuests: stats.guest_count > 0,
let dmUser;
let gmMembers;
if (channel && channel.type === General.DM_CHANNEL) {
const dmUserId = getUserIdFromChannelName(user.id, channel.name);
dmUser = getUser(state, dmUserId);
} else if (channel && channel.type === General.GM_CHANNEL) {
gmMembers = doGetProfilesInChannel(state, channel.id, true);
}
const stats = getCurrentChannelStats(state) || {member_count: 0, guest_count: 0};

return {
teamId: getCurrentTeamId(state),
channel,
channelMember: getMyCurrentChannelMembership(state),
currentUser: user,
dmUser,
gmMembers,
rhsState: getRhsState(state),
isFavorite: isCurrentChannelFavorite(state),
isReadOnly: isCurrentChannelReadOnly(state),
isMuted: isCurrentChannelMuted(state),
isQuickSwitcherOpen: isModalOpen(state, ModalIdentifiers.QUICK_SWITCH),
hasGuests: stats.guest_count > 0,
};
};
};
}

const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators({
Expand All @@ -84,4 +93,4 @@ const mapDispatchToProps = (dispatch) => ({
}, dispatch),
});

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ChannelHeader));
export default withRouter(connect(makeMapStateToProps, mapDispatchToProps)(ChannelHeader));

0 comments on commit f8cf9c5

Please sign in to comment.