From 86fbd496af8ff646bcff8484ad1733101333e8c6 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 7 Apr 2017 14:21:31 -0400 Subject: Check if we need to add DM/GM to sidebar regardless of post sender (#6009) --- webapp/actions/user_actions.jsx | 49 +++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'webapp/actions/user_actions.jsx') diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 1ab85922d..70df4776e 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -11,7 +11,7 @@ import ChannelStore from 'stores/channel_store.jsx'; import {getChannelMembersForUserIds} from 'actions/channel_actions.jsx'; import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx'; -import {getDirectChannelName} from 'utils/utils.jsx'; +import {getDirectChannelName, getUserIdFromChannelName} from 'utils/utils.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import Client from 'client/web_client.jsx'; @@ -255,24 +255,45 @@ function populateChannelWithProfiles(channelId, userIds) { UserStore.emitInChannelChange(); } -export function loadNewDMIfNeeded(userId) { - if (userId === UserStore.getCurrentId()) { - return; - } +export function loadNewDMIfNeeded(channelId) { + function checkPreference(channel) { + const userId = getUserIdFromChannelName(channel); + + if (!userId) { + return; + } - const pref = PreferenceStore.getBool(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'); - loadProfilesForDM(); + const pref = PreferenceStore.getBool(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'); + loadProfilesForDM(); + } } -} -export function loadNewGMIfNeeded(channelId, userId) { - if (userId === UserStore.getCurrentId()) { - return; + const channel = ChannelStore.get(channelId); + if (channel) { + checkPreference(channel); + } else { + Client.getChannel( + channelId, + (data) => { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_CHANNEL, + channel: data.channel, + member: data.member + }); + + checkPreference(data.channel); + }, + (err) => { + AsyncClient.dispatchError(err, 'getChannel'); + } + ); } +} +export function loadNewGMIfNeeded(channelId) { function checkPreference() { const pref = PreferenceStore.getBool(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId, false); if (pref === false) { -- cgit v1.2.3-1-g7c22