mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Prevent unnecessary store emits (#6285)
* Remove unnecessary store emits * Drastically reduce number of emitted changes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user