diff --git a/app/components/channel_intro/index.js b/app/components/channel_intro/index.js index 47a20cda6..2972a7eef 100644 --- a/app/components/channel_intro/index.js +++ b/app/components/channel_intro/index.js @@ -2,9 +2,11 @@ // See License.txt for license information. import {connect} from 'react-redux'; +import {createSelector} from 'reselect'; + import {General, RequestStatus} from 'mattermost-redux/constants'; import {makeGetChannel} from 'mattermost-redux/selectors/entities/channels'; -import {getCurrentUser, makeGetProfilesInChannel} from 'mattermost-redux/selectors/entities/users'; +import {getCurrentUserId, getUser, makeGetProfilesInChannel} from 'mattermost-redux/selectors/entities/users'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; @@ -14,31 +16,62 @@ function makeMapStateToProps() { const getChannel = makeGetChannel(); const getProfilesInChannel = makeGetProfilesInChannel(); + const getOtherUserIdForDm = createSelector( + (state, channel) => channel, + getCurrentUserId, + (channel, currentUserId) => { + if (!channel) { + return ''; + } + + return channel.name.split('__').find((m) => m !== currentUserId); + } + ); + + const getChannelMembers = createSelector( + getCurrentUserId, + (state, channel) => getProfilesInChannel(state, channel.id), + (currentUserId, profilesInChannel) => { + const currentChannelMembers = profilesInChannel || []; + return currentChannelMembers.filter((m) => m.id !== currentUserId); + } + ); + + const getChannelMembersForDm = createSelector( + (state, channel) => getUser(state, getOtherUserIdForDm(state, channel)), + (otherUser) => { + if (!otherUser) { + return []; + } + + return [otherUser]; + } + ); + return function mapStateToProps(state, ownProps) { const currentChannel = getChannel(state, {id: ownProps.channelId}) || {}; - const currentUser = getCurrentUser(state) || {}; const {status: getPostsRequestStatus} = state.requests.posts.getPosts; - let currentChannelMembers = []; - if (currentChannel.type === General.DM_CHANNEL) { - const otherChannelMember = currentChannel.name.split('__').find((m) => m !== currentUser.id); - const otherProfile = state.entities.users.profiles[otherChannelMember]; - if (otherProfile) { - currentChannelMembers.push(otherProfile); - } - } else { - currentChannelMembers = getProfilesInChannel(state, ownProps.channelId) || []; - currentChannelMembers = currentChannelMembers.filter((m) => m.id !== currentUser.id); - } + let currentChannelMembers; + let creator; + let postsInChannel; - const creator = currentChannel.creator_id === currentUser.id ? currentUser : state.entities.users.profiles[currentChannel.creator_id]; - const postsInChannel = state.entities.posts.postsInChannel[ownProps.channelId] || []; + if (currentChannel) { + if (currentChannel.type === General.DM_CHANNEL) { + currentChannelMembers = getChannelMembersForDm(state, currentChannel); + } else { + currentChannelMembers = getChannelMembers(state, currentChannel); + } + + creator = getUser(state, currentChannel.creator_id); + postsInChannel = state.entities.posts.postsInChannel[currentChannel.Id]; + } return { creator, currentChannel, currentChannelMembers, - isLoadingPosts: !postsInChannel.length && getPostsRequestStatus === RequestStatus.STARTED, + isLoadingPosts: (!postsInChannel || postsInChannel.length === 0) && getPostsRequestStatus === RequestStatus.STARTED, theme: getTheme(state) }; }; diff --git a/app/components/post_list/post_list.js b/app/components/post_list/post_list.js index 59c887b51..8d1428c83 100644 --- a/app/components/post_list/post_list.js +++ b/app/components/post_list/post_list.js @@ -14,6 +14,7 @@ import ChannelIntro from 'app/components/channel_intro'; import Post from 'app/components/post'; import {DATE_LINE, START_OF_NEW_MESSAGES} from 'app/selectors/post_list'; import mattermostManaged from 'app/mattermost_managed'; +import {makeExtraData} from 'app/utils/list_view'; import DateHeader from './date_header'; import LoadMorePosts from './load_more_posts'; @@ -49,6 +50,9 @@ export default class PostList extends PureComponent { super(props); this.newMessagesIndex = -1; + + this.makeExtraData = makeExtraData(); + this.state = { managedConfig: {} }; @@ -233,7 +237,7 @@ export default class PostList extends PureComponent { { + if (!shallowEqual(lastArgs, args)) { + lastArgs = args; + } + + return lastArgs; + }; +}