From db2966b7cb3111ff1b3cadfbec1221343b0e8629 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 15 Feb 2017 18:54:24 -0500 Subject: Remove MakeDirectChannelVisible and add client handling for showing DMs (#5430) --- webapp/actions/post_actions.jsx | 5 +++++ webapp/actions/user_actions.jsx | 46 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) (limited to 'webapp/actions') diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx index 633a6f66a..81ef73fc5 100644 --- a/webapp/actions/post_actions.jsx +++ b/webapp/actions/post_actions.jsx @@ -8,6 +8,7 @@ import PostStore from 'stores/post_store.jsx'; import UserStore from 'stores/user_store.jsx'; import {loadStatusesForChannel} from 'actions/status_actions.jsx'; +import {loadNewDMIfNeeded} from 'actions/user_actions.jsx'; import Client from 'client/web_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; @@ -22,6 +23,10 @@ export function handleNewPost(post, msg) { websocketMessageProps = msg.data; } + if (msg && msg.data && msg.data.channel_type === Constants.DM_CHANNEL) { + loadNewDMIfNeeded(post.user_id); + } + if (post.root_id && PostStore.getPost(post.channel_id, post.root_id) == null) { Client.getPost( post.channel_id, 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, -- cgit v1.2.3-1-g7c22