diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-05-01 10:49:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-01 10:49:34 -0400 |
commit | 2d22fb5652e547b4fe169dee2ea9cd14f747a485 (patch) | |
tree | a27e0a814ca2563ca9d20970201e397aa88afc6f /webapp/actions | |
parent | 83f819451a80a767170b927eb2f0d5ed63f03239 (diff) | |
download | chat-2d22fb5652e547b4fe169dee2ea9cd14f747a485.tar.gz chat-2d22fb5652e547b4fe169dee2ea9cd14f747a485.tar.bz2 chat-2d22fb5652e547b4fe169dee2ea9cd14f747a485.zip |
Prevent unnecessary store emits (#6285)
* Remove unnecessary store emits
* Drastically reduce number of emitted changes
Diffstat (limited to 'webapp/actions')
-rw-r--r-- | webapp/actions/channel_actions.jsx | 2 | ||||
-rw-r--r-- | webapp/actions/global_actions.jsx | 11 | ||||
-rw-r--r-- | webapp/actions/user_actions.jsx | 5 |
3 files changed, 10 insertions, 8 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx index 79dfe3212..6acb05454 100644 --- a/webapp/actions/channel_actions.jsx +++ b/webapp/actions/channel_actions.jsx @@ -90,7 +90,7 @@ export function executeCommand(message, args, success, error) { export function setChannelAsRead(channelIdParam) { const channelId = channelIdParam || ChannelStore.getCurrentId(); viewChannel(channelId)(dispatch, getState); - ChannelStore.resetCounts(channelId); + ChannelStore.resetCounts([channelId]); ChannelStore.emitChange(); if (channelId === ChannelStore.getCurrentId()) { ChannelStore.emitLastViewed(Number.MAX_VALUE, false); diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx index 1dd5d6952..97d3b1071 100644 --- a/webapp/actions/global_actions.jsx +++ b/webapp/actions/global_actions.jsx @@ -36,7 +36,7 @@ import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; import {removeUserFromTeam} from 'mattermost-redux/actions/teams'; -import {viewChannel, getChannelStats, getChannelMember} from 'mattermost-redux/actions/channels'; +import {viewChannel, getChannelStats, getMyChannelMember} from 'mattermost-redux/actions/channels'; export function emitChannelClickEvent(channel) { function userVisitedFakeChannel(chan, success, fail) { @@ -53,23 +53,22 @@ export function emitChannelClickEvent(channel) { } function switchToChannel(chan) { const channelMember = ChannelStore.getMyMember(chan.id); - const getMyChannelMemberPromise = getChannelMember(chan.id, UserStore.getCurrentId())(dispatch, getState); + const getMyChannelMemberPromise = getMyChannelMember(chan.id)(dispatch, getState); const oldChannelId = ChannelStore.getCurrentId(); getMyChannelMemberPromise.then(() => { getChannelStats(chan.id)(dispatch, getState); viewChannel(chan.id)(dispatch, getState); loadPosts(chan.id); + + // Mark previous and next channel as read + ChannelStore.resetCounts([chan.id, oldChannelId]); }); // Subtract mentions for the team const {msgs, mentions} = ChannelStore.getUnreadCounts()[chan.id] || {msgs: 0, mentions: 0}; TeamStore.subtractUnread(chan.team_id, msgs, mentions); - // Mark previous and next channel as read - ChannelStore.resetCounts(oldChannelId); - ChannelStore.resetCounts(chan.id); - BrowserStore.setGlobalItem(chan.team_id, chan.id); loadProfilesForSidebar(); diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index eacb0df80..8dfc819b9 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -24,6 +24,8 @@ import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; +import * as Selectors from 'mattermost-redux/selectors/entities/users'; + import { getProfiles, getProfilesInChannel, @@ -239,7 +241,8 @@ function populateDMChannelsWithProfiles(userIds) { for (let i = 0; i < userIds.length; i++) { const channelName = getDirectChannelName(currentUserId, userIds[i]); const channel = ChannelStore.getByName(channelName); - if (channel) { + const profilesInChannel = Selectors.getUserIdsInChannels(getState())[channel.id] || new Set(); + if (channel && !profilesInChannel.has(userIds[i])) { UserStore.saveUserIdInChannel(channel.id, userIds[i]); } } |