summaryrefslogtreecommitdiffstats
path: root/webapp/actions/user_actions.jsx
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-15 18:54:24 -0500
committerGitHub <noreply@github.com>2017-02-15 18:54:24 -0500
commitdb2966b7cb3111ff1b3cadfbec1221343b0e8629 (patch)
treee2b64183860e98807a4d77401db3dcdf61d2a6a7 /webapp/actions/user_actions.jsx
parent745e2f4923c653c7b9bff990375d9f3f67b4c212 (diff)
downloadchat-db2966b7cb3111ff1b3cadfbec1221343b0e8629.tar.gz
chat-db2966b7cb3111ff1b3cadfbec1221343b0e8629.tar.bz2
chat-db2966b7cb3111ff1b3cadfbec1221343b0e8629.zip
Remove MakeDirectChannelVisible and add client handling for showing DMs (#5430)
Diffstat (limited to 'webapp/actions/user_actions.jsx')
-rw-r--r--webapp/actions/user_actions.jsx46
1 files changed, 45 insertions, 1 deletions
diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx
index 94777bc45..43881a188 100644
--- a/webapp/actions/user_actions.jsx
+++ b/webapp/actions/user_actions.jsx
@@ -16,7 +16,7 @@ import {getDirectChannelName} from 'utils/utils.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
-import {ActionTypes, Preferences} from 'utils/constants.jsx';
+import {Constants, ActionTypes, Preferences} from 'utils/constants.jsx';
import {browserHistory} from 'react-router/es6';
export function switchFromLdapToEmail(email, password, token, ldapPassword, onSuccess, onError) {
@@ -225,6 +225,19 @@ function populateDMChannelsWithProfiles(userIds) {
}
}
+export function loadNewDMIfNeeded(userId) {
+ if (userId === UserStore.getCurrentId()) {
+ return;
+ }
+
+ const pref = PreferenceStore.get(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'false');
+ if (pref === 'false') {
+ PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
+ AsyncClient.savePreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
+ loadProfilesAndTeamMembersForDMSidebar();
+ }
+}
+
export function loadProfilesAndTeamMembersForDMSidebar() {
const dmPrefs = PreferenceStore.getCategory(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW);
const teamId = TeamStore.getCurrentId();
@@ -240,6 +253,37 @@ export function loadProfilesAndTeamMembersForDMSidebar() {
}
}
+ const channelMembers = ChannelStore.getMyMembers();
+ const channels = ChannelStore.getChannels();
+ const newPreferences = [];
+ for (let i = 0; i < channels.length; i++) {
+ const channel = channels[i];
+ if (channel.type !== Constants.DM_CHANNEL) {
+ continue;
+ }
+
+ const member = channelMembers[channel.id];
+ if (!member) {
+ continue;
+ }
+
+ const teammateId = channel.name.replace(member.user_id, '').replace('__', '');
+
+ 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 (newPreferences.length > 0) {
+ AsyncClient.savePreferences(newPreferences);
+ }
+
if (profilesToLoad.length > 0) {
Client.getProfilesByIds(
profilesToLoad,