Skip to content

Commit

Permalink
Check if LHS DM list needs updating on channel switch and channel mem…
Browse files Browse the repository at this point in the history
…bers fetch
  • Loading branch information
jwilander committed Mar 23, 2017
1 parent a12e7fd commit 3f4f0f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 2 additions & 0 deletions webapp/actions/global_actions.jsx
Expand Up @@ -62,6 +62,8 @@ export function emitChannelClickEvent(channel) {

BrowserStore.setGlobalItem(chan.team_id, chan.id);

loadProfilesAndTeamMembersForDMSidebar();

AppDispatcher.handleViewAction({
type: ActionTypes.CLICK_CHANNEL,
name: chan.name,
Expand Down
38 changes: 18 additions & 20 deletions webapp/actions/user_actions.jsx
Expand Up @@ -157,21 +157,15 @@ export function loadNewDMIfNeeded(userId) {
}
}

function isMissingTeamMember(teamId, userId) {
return !TeamStore.hasActiveMemberInTeam(teamId, userId) && !TeamStore.hasMemberNotInTeam(teamId, userId);
}

export function loadProfilesAndTeamMembersForDMSidebar() {
const dmPrefs = PreferenceStore.getCategory(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW);
const teamId = TeamStore.getCurrentId();
const profilesToLoad = [];
const membersToLoad = [];

for (const [key, value] of dmPrefs) {
if (value === 'true') {
if (!UserStore.hasProfile(key)) {
profilesToLoad.push(key);
}
membersToLoad.push(key);
}
}

const channelMembers = ChannelStore.getMyMembers();
const channels = ChannelStore.getChannels();
const newPreferences = [];
Expand All @@ -181,25 +175,29 @@ export function loadProfilesAndTeamMembersForDMSidebar() {
continue;
}

const member = channelMembers[channel.id];
if (!member) {
continue;
const teammateId = channel.name.replace(UserStore.getCurrentId(), '').replace('__', '');
const isVisible = PreferenceStore.getBool(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, teammateId);

if (isMissingTeamMember(teamId, teammateId)) {
membersToLoad.push(teammateId);
}

const teammateId = channel.name.replace(member.user_id, '').replace('__', '');
if (!UserStore.hasProfile(teammateId)) {
profilesToLoad.push(teammateId);
}

if (!isVisible) {
const member = channelMembers[channel.id];
if (!member || member.mention_count === 0) {
continue;
}

if (member.mention_count > 0 && membersToLoad.indexOf(teammateId) === -1) {
membersToLoad.push(teammateId);
newPreferences.push({
user_id: UserStore.getCurrentId(),
category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
name: teammateId,
value: 'true'
});

if (!UserStore.hasProfile(teammateId)) {
profilesToLoad.push(teammateId);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion webapp/components/needs_team.jsx
Expand Up @@ -15,6 +15,7 @@ import ChannelStore from 'stores/channel_store.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {startPeriodicStatusUpdates, stopPeriodicStatusUpdates} from 'actions/status_actions.jsx';
import {startPeriodicSync, stopPeriodicSync} from 'actions/websocket_actions.jsx';
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';

import Constants from 'utils/constants.jsx';
const TutorialSteps = Constants.TutorialSteps;
Expand Down Expand Up @@ -107,7 +108,7 @@ export default class NeedsTeam extends React.Component {

window.isActive = true;
if (new Date().getTime() - this.blurTime > UNREAD_CHECK_TIME_MILLISECONDS) {
AsyncClient.getMyChannelMembers();
AsyncClient.getMyChannelMembers().then(loadProfilesAndTeamMembersForDMSidebar);
}
});

Expand Down

0 comments on commit 3f4f0f1

Please sign in to comment.