Skip to content

Commit

Permalink
Improve perf for channel switching, fix team switching issues (matter…
Browse files Browse the repository at this point in the history
…most#6286)

* Improve perf for channel switching, fix team switching issues

* Fix last channel when switching teams
  • Loading branch information
jwilander authored and hmhealey committed May 2, 2017
1 parent 294bd08 commit 042052a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
4 changes: 2 additions & 2 deletions webapp/actions/post_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions webapp/components/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion webapp/stores/channel_store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class ChannelStoreClass extends EventEmitter {
}

getChannelById(id) {
return Selectors.getChannelsInCurrentTeam(store.getState())[id];
return this.get(id);
}

storeMyChannelMember(channelMember) {
Expand Down
19 changes: 0 additions & 19 deletions webapp/stores/team_store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 042052a

Please sign in to comment.