Remove MakeDirectChannelVisible and add client handling for showing DMs (#5430)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
745e2f4923
Коммит
db2966b7cb
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -12,6 +12,7 @@ import * as GlobalActions from 'actions/global_actions.jsx';
|
||||
import * as Websockets from 'actions/websocket_actions.jsx';
|
||||
import BrowserStore from 'stores/browser_store.jsx';
|
||||
import ChannelStore from 'stores/channel_store.jsx';
|
||||
import UserStore from 'stores/user_store.jsx';
|
||||
import * as I18n from 'i18n/i18n.jsx';
|
||||
import * as AsyncClient from 'utils/async_client.jsx';
|
||||
|
||||
@@ -60,7 +61,9 @@ function preRenderSetup(callwhendone) {
|
||||
$(window).on('beforeunload',
|
||||
() => {
|
||||
BrowserStore.setLastServerVersion('');
|
||||
AsyncClient.viewChannel('', ChannelStore.getCurrentId() || '');
|
||||
if (UserStore.getCurrentUser()) {
|
||||
AsyncClient.viewChannel('', ChannelStore.getCurrentId() || '');
|
||||
}
|
||||
Websockets.close();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -13,6 +13,7 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
||||
import Constants from 'utils/constants.jsx';
|
||||
const ActionTypes = Constants.ActionTypes;
|
||||
import * as AsyncClient from 'utils/async_client.jsx';
|
||||
import * as Utils from 'utils/utils.jsx';
|
||||
import Client from 'client/web_client.jsx';
|
||||
import ChannelStore from 'stores/channel_store.jsx';
|
||||
import BrowserStore from 'stores/browser_store.jsx';
|
||||
@@ -20,7 +21,7 @@ import BrowserStore from 'stores/browser_store.jsx';
|
||||
import emojiRoute from 'routes/route_emoji.jsx';
|
||||
import integrationsRoute from 'routes/route_integrations.jsx';
|
||||
|
||||
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
|
||||
import {loadNewDMIfNeeded, loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
|
||||
|
||||
function onChannelEnter(nextState, replace, callback) {
|
||||
doChannelChange(nextState, replace, callback);
|
||||
@@ -33,6 +34,10 @@ function doChannelChange(state, replace, callback) {
|
||||
} else {
|
||||
channel = ChannelStore.getByName(state.params.channel);
|
||||
|
||||
if (channel.type === Constants.DM_CHANNEL) {
|
||||
loadNewDMIfNeeded(Utils.getUserIdFromChannelName(channel));
|
||||
}
|
||||
|
||||
if (!channel) {
|
||||
Client.joinChannelByName(
|
||||
state.params.channel,
|
||||
@@ -100,7 +105,6 @@ function preNeedsTeam(nextState, replace, callback) {
|
||||
|
||||
if (nextState.location.pathname.indexOf('/channels/') > -1 ||
|
||||
nextState.location.pathname.indexOf('/pl/') > -1) {
|
||||
loadProfilesAndTeamMembersForDMSidebar();
|
||||
AsyncClient.getMyTeamsUnread();
|
||||
const teams = TeamStore.getAll();
|
||||
for (const id in teams) {
|
||||
@@ -120,6 +124,7 @@ function preNeedsTeam(nextState, replace, callback) {
|
||||
});
|
||||
|
||||
loadStatusesForChannelAndSidebar();
|
||||
loadProfilesAndTeamMembersForDMSidebar();
|
||||
|
||||
d1.resolve();
|
||||
},
|
||||
|
||||
Ссылка в новой задаче
Block a user