From 042052aec61b8c51751cb3aeb27c6c21ecf16416 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 2 May 2017 09:28:44 -0400 Subject: Improve perf for channel switching, fix team switching issues (#6286) * Improve perf for channel switching, fix team switching issues * Fix last channel when switching teams --- webapp/actions/post_actions.jsx | 4 ++-- webapp/components/sidebar.jsx | 11 ++++++++--- webapp/stores/channel_store.jsx | 2 +- webapp/stores/team_store.jsx | 19 ------------------- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx index 4b7ade862..3174fe681 100644 --- a/webapp/actions/post_actions.jsx +++ b/webapp/actions/post_actions.jsx @@ -25,7 +25,7 @@ import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; import {getProfilesByIds} from 'mattermost-redux/actions/users'; -import {getChannelMember} from 'mattermost-redux/actions/channels'; +import {getMyChannelMember} from 'mattermost-redux/actions/channels'; export function handleNewPost(post, msg) { let websocketMessageProps = {}; @@ -41,7 +41,7 @@ export function handleNewPost(post, msg) { Client.setTeamId(msg.data.team_id); } - getChannelMember(post.channel_id, UserStore.getCurrentId())(dispatch, getState).then(() => completePostReceive(post, websocketMessageProps)); + getMyChannelMember(post.channel_id)(dispatch, getState).then(() => completePostReceive(post, websocketMessageProps)); } if (msg && msg.data) { diff --git a/webapp/components/sidebar.jsx b/webapp/components/sidebar.jsx index 71559de02..465d25576 100644 --- a/webapp/components/sidebar.jsx +++ b/webapp/components/sidebar.jsx @@ -116,14 +116,19 @@ export default class Sidebar extends React.Component { const currentChannelId = ChannelStore.getCurrentId(); const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 999); - const allChannels = ChannelStore.getAll().map((channel) => Object.assign({}, channel)); - const channelList = ChannelUtils.buildDisplayableChannelList(allChannels); + const channels = ChannelStore.getAll(); + let displayableChannels = {}; + if (channels !== this.oldChannels) { + const channelsArray = channels.map((channel) => Object.assign({}, channel)); + displayableChannels = ChannelUtils.buildDisplayableChannelList(channelsArray); + } + this.oldChannels = channels; return { activeId: currentChannelId, members, teamMembers, - ...channelList, + ...displayableChannels, unreadCounts: JSON.parse(JSON.stringify(ChannelStore.getUnreadCounts())), showTutorialTip: tutorialStep === TutorialSteps.CHANNEL_POPOVER, currentTeam: TeamStore.getCurrent(), diff --git a/webapp/stores/channel_store.jsx b/webapp/stores/channel_store.jsx index 1440c1590..db1bead46 100644 --- a/webapp/stores/channel_store.jsx +++ b/webapp/stores/channel_store.jsx @@ -261,7 +261,7 @@ class ChannelStoreClass extends EventEmitter { } getChannelById(id) { - return Selectors.getChannelsInCurrentTeam(store.getState())[id]; + return this.get(id); } storeMyChannelMember(channelMember) { diff --git a/webapp/stores/team_store.jsx b/webapp/stores/team_store.jsx index f017c411e..2dc034199 100644 --- a/webapp/stores/team_store.jsx +++ b/webapp/stores/team_store.jsx @@ -342,20 +342,6 @@ class TeamStoreClass extends EventEmitter { return false; } - updateUnreadCount(teamId, totalMsgCount, channelMember) { - let member = this.getMyTeamMembers().filter((m) => m.team_id === teamId)[0]; - if (member) { - member = Object.assign({}, member); - member.msg_count -= (totalMsgCount - channelMember.msg_count); - member.mention_count -= channelMember.mention_count; - - store.dispatch({ - type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, - data: member - }); - } - } - subtractUnread(teamId, msgs, mentions) { let member = this.getMyTeamMembers().filter((m) => m.team_id === teamId)[0]; if (member) { @@ -443,11 +429,6 @@ TeamStore.dispatchToken = AppDispatcher.register((payload) => { case ActionTypes.RECEIVED_TEAM_STATS: TeamStore.saveStats(action.team_id, action.stats); break; - case ActionTypes.CLICK_CHANNEL: - if (action.channelMember) { - TeamStore.updateUnreadCount(action.team_id, action.total_msg_count, action.channelMember); - } - break; case ActionTypes.RECEIVED_POST: if (action.post.type === PostTypes.JOIN_LEAVE || action.post.type === PostTypes.JOIN_CHANNEL || action.post.type === PostTypes.LEAVE_CHANNEL) { return; -- cgit v1.2.3-1-g7c22