Merge pull request #1652 from hmhealey/plt1319
PLT-1319 Fixed direct channels not being visible when no actual channel exists
Этот коммит содержится в:
@@ -71,49 +71,47 @@ export default class Sidebar extends React.Component {
|
||||
getStateFromStores() {
|
||||
const members = ChannelStore.getAllMembers();
|
||||
const currentChannelId = ChannelStore.getCurrentId();
|
||||
const currentUserId = UserStore.getCurrentId();
|
||||
|
||||
const channels = Object.assign([], ChannelStore.getAll());
|
||||
channels.sort((a, b) => a.display_name.localeCompare(b.display_name));
|
||||
|
||||
const publicChannels = channels.filter((channel) => channel.type === Constants.OPEN_CHANNEL);
|
||||
const privateChannels = channels.filter((channel) => channel.type === Constants.PRIVATE_CHANNEL);
|
||||
const directChannels = channels.filter((channel) => channel.type === Constants.DM_CHANNEL);
|
||||
|
||||
const preferences = PreferenceStore.getPreferences(Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW);
|
||||
|
||||
var visibleDirectChannels = [];
|
||||
for (var i = 0; i < directChannels.length; i++) {
|
||||
const dm = directChannels[i];
|
||||
const teammate = Utils.getDirectTeammate(dm.id);
|
||||
if (!teammate) {
|
||||
const directChannels = [];
|
||||
for (const preference of preferences) {
|
||||
if (preference.value !== 'true') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const member = members[dm.id];
|
||||
const msgCount = dm.total_msg_count - member.msg_count;
|
||||
const teammateId = preference.name;
|
||||
|
||||
// always show a channel if either it is the current one or if it is unread, but it is not currently being left
|
||||
const forceShow = (currentChannelId === dm.id || msgCount > 0) && !this.isLeaving.get(dm.id);
|
||||
const preferenceShow = preferences.some((preference) => (preference.name === teammate.id && preference.value !== 'false'));
|
||||
let directChannel = channels.find(Utils.isDirectChannelForUser.bind(null, teammateId));
|
||||
|
||||
if (preferenceShow || forceShow) {
|
||||
dm.display_name = Utils.displayUsername(teammate.id);
|
||||
dm.teammate_id = teammate.id;
|
||||
dm.status = UserStore.getStatus(teammate.id);
|
||||
|
||||
visibleDirectChannels.push(dm);
|
||||
|
||||
if (forceShow && !preferenceShow) {
|
||||
// make sure that unread direct channels are visible
|
||||
const preference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, teammate.id, 'true');
|
||||
AsyncClient.savePreferences([preference]);
|
||||
}
|
||||
// a direct channel doesn't exist yet so create a fake one
|
||||
if (!directChannel) {
|
||||
directChannel = {
|
||||
name: Utils.getDirectChannelName(currentUserId, teammateId),
|
||||
last_post_at: 0,
|
||||
total_msg_count: 0,
|
||||
type: Constants.DM_CHANNEL,
|
||||
fake: true
|
||||
};
|
||||
}
|
||||
|
||||
directChannel.display_name = Utils.displayUsername(teammateId);
|
||||
directChannel.teammate_id = teammateId;
|
||||
directChannel.status = UserStore.getStatus(teammateId);
|
||||
|
||||
directChannels.push(directChannel);
|
||||
}
|
||||
|
||||
const hiddenDirectChannelCount = UserStore.getActiveOnlyProfileList(true).length - visibleDirectChannels.length;
|
||||
directChannels.sort(this.sortChannelsByDisplayName);
|
||||
|
||||
visibleDirectChannels.sort(this.sortChannelsByDisplayName);
|
||||
const hiddenDirectChannelCount = UserStore.getActiveOnlyProfileList(true).length - directChannels.length;
|
||||
|
||||
const tutorialPref = PreferenceStore.getPreference(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), {value: '999'});
|
||||
|
||||
@@ -122,7 +120,7 @@ export default class Sidebar extends React.Component {
|
||||
members,
|
||||
publicChannels,
|
||||
privateChannels,
|
||||
visibleDirectChannels,
|
||||
directChannels,
|
||||
hiddenDirectChannelCount,
|
||||
unreadCounts: JSON.parse(JSON.stringify(ChannelStore.getUnreadCounts())),
|
||||
showTutorialTip: parseInt(tutorialPref.value, 10) === TutorialSteps.CHANNEL_POPOVER
|
||||
@@ -484,7 +482,7 @@ export default class Sidebar extends React.Component {
|
||||
|
||||
const privateChannelItems = this.state.privateChannels.map(this.createChannelElement);
|
||||
|
||||
const directMessageItems = this.state.visibleDirectChannels.map((channel, index, arr) => {
|
||||
const directMessageItems = this.state.directChannels.map((channel, index, arr) => {
|
||||
return this.createChannelElement(channel, index, arr, this.handleLeaveDirectChannel);
|
||||
});
|
||||
|
||||
|
||||
@@ -173,3 +173,10 @@ export function emitClearSuggestions(suggestionId) {
|
||||
id: suggestionId
|
||||
});
|
||||
}
|
||||
|
||||
export function emitPreferenceChangedEvent(preference) {
|
||||
AppDispatcher.handleServerAction({
|
||||
type: Constants.ActionTypes.RECIEVED_PREFERENCE,
|
||||
preference
|
||||
});
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ class PreferenceStoreClass extends EventEmitter {
|
||||
return preference;
|
||||
}
|
||||
|
||||
emitChange(preferences) {
|
||||
this.emit(CHANGE_EVENT, preferences);
|
||||
emitChange() {
|
||||
this.emit(CHANGE_EVENT);
|
||||
}
|
||||
|
||||
addChangeListener(callback) {
|
||||
@@ -106,6 +106,12 @@ class PreferenceStoreClass extends EventEmitter {
|
||||
const action = payload.action;
|
||||
|
||||
switch (action.type) {
|
||||
case ActionTypes.RECIEVED_PREFERENCE: {
|
||||
const preference = action.preference;
|
||||
this.setPreference(preference.category, preference.name, preference.value);
|
||||
this.emitChange();
|
||||
break;
|
||||
}
|
||||
case ActionTypes.RECIEVED_PREFERENCES: {
|
||||
const preferences = this.getAllPreferences();
|
||||
|
||||
@@ -114,7 +120,7 @@ class PreferenceStoreClass extends EventEmitter {
|
||||
}
|
||||
|
||||
this.setAllPreferences(preferences);
|
||||
this.emitChange(preferences);
|
||||
this.emitChange();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,10 @@ class SocketStoreClass extends EventEmitter {
|
||||
handleChannelViewedEvent(msg);
|
||||
break;
|
||||
|
||||
case SocketEvents.PREFERENCE_CHANGED:
|
||||
handlePreferenceChangedEvent(msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
@@ -281,6 +285,11 @@ function handleChannelViewedEvent(msg) {
|
||||
}
|
||||
}
|
||||
|
||||
function handlePreferenceChangedEvent(msg) {
|
||||
const preference = JSON.parse(msg.props.preference);
|
||||
EventHelpers.emitPreferenceChangedEvent(preference);
|
||||
}
|
||||
|
||||
var SocketStore = new SocketStoreClass();
|
||||
|
||||
/*SocketStore.dispatchToken = AppDispatcher.register((payload) => {
|
||||
|
||||
@@ -35,6 +35,7 @@ export default {
|
||||
RECIEVED_AUDITS: null,
|
||||
RECIEVED_TEAMS: null,
|
||||
RECIEVED_STATUSES: null,
|
||||
RECIEVED_PREFERENCE: null,
|
||||
RECIEVED_PREFERENCES: null,
|
||||
|
||||
RECIEVED_MSG: null,
|
||||
@@ -74,7 +75,8 @@ export default {
|
||||
NEW_USER: 'new_user',
|
||||
USER_ADDED: 'user_added',
|
||||
USER_REMOVED: 'user_removed',
|
||||
TYPING: 'typing'
|
||||
TYPING: 'typing',
|
||||
PREFERENCE_CHANGED: 'preference_changed'
|
||||
},
|
||||
|
||||
//SPECIAL_MENTIONS: ['all', 'channel'],
|
||||
|
||||
@@ -1138,6 +1138,11 @@ export function getUserIdFromChannelName(channel) {
|
||||
return otherUserId;
|
||||
}
|
||||
|
||||
// Returns true if the given channel is a direct channel between the current user and the given one
|
||||
export function isDirectChannelForUser(otherUserId, channel) {
|
||||
return channel.type === Constants.DM_CHANNEL && getUserIdFromChannelName(channel) === otherUserId;
|
||||
}
|
||||
|
||||
export function importSlack(file, success, error) {
|
||||
var formData = new FormData();
|
||||
formData.append('file', file, file.name);
|
||||
|
||||
Ссылка в новой задаче
Block a user