Fix autocomplete for old mechanisms and add partial fix for channel switcher (#4279)
Этот коммит содержится в:
коммит произвёл
enahum
родитель
4688d4981a
Коммит
4aa96c76b4
@@ -118,7 +118,7 @@ export function removeUserFromChannel(channelId, userId, success, error) {
|
|||||||
|
|
||||||
export function openDirectChannelToUser(user, success, error) {
|
export function openDirectChannelToUser(user, success, error) {
|
||||||
const channelName = Utils.getDirectChannelName(UserStore.getCurrentId(), user.id);
|
const channelName = Utils.getDirectChannelName(UserStore.getCurrentId(), user.id);
|
||||||
let channel = ChannelStore.getByName(channelName);
|
const channel = ChannelStore.getByName(channelName);
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, user.id, 'true');
|
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, user.id, 'true');
|
||||||
@@ -137,16 +137,6 @@ export function openDirectChannelToUser(user, success, error) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = {
|
|
||||||
name: channelName,
|
|
||||||
last_post_at: 0,
|
|
||||||
total_msg_count: 0,
|
|
||||||
type: 'D',
|
|
||||||
display_name: user.username,
|
|
||||||
teammate_id: user.id,
|
|
||||||
status: UserStore.getStatus(user.id)
|
|
||||||
};
|
|
||||||
|
|
||||||
Client.createDirectChannel(
|
Client.createDirectChannel(
|
||||||
user.id,
|
user.id,
|
||||||
(data) => {
|
(data) => {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import * as Utils from 'utils/utils.jsx';
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
|
|
||||||
export default class SwitchChannelModal extends React.Component {
|
export default class SwitchChannelModal extends React.Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -28,6 +29,8 @@ export default class SwitchChannelModal extends React.Component {
|
|||||||
this.onExited = this.onExited.bind(this);
|
this.onExited = this.onExited.bind(this);
|
||||||
this.handleKeyDown = this.handleKeyDown.bind(this);
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
|
this.switchToChannel = this.switchToChannel.bind(this);
|
||||||
|
|
||||||
this.suggestionProviders = [new SwitchChannelProvider()];
|
this.suggestionProviders = [new SwitchChannelProvider()];
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -92,16 +95,21 @@ export default class SwitchChannelModal extends React.Component {
|
|||||||
user,
|
user,
|
||||||
(ch) => {
|
(ch) => {
|
||||||
channel = ch;
|
channel = ch;
|
||||||
|
this.switchToChannel(channel);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
channel = null;
|
channel = null;
|
||||||
|
this.switchToChannel(channel);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
channel = ChannelStore.getByName(this.state.text.trim());
|
channel = ChannelStore.getByName(this.state.text.trim());
|
||||||
|
this.switchToChannel(channel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switchToChannel(channel) {
|
||||||
if (channel !== null) {
|
if (channel !== null) {
|
||||||
goToChannel(channel);
|
goToChannel(channel);
|
||||||
this.onHide();
|
this.onHide();
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ export default class ChannelMentionProvider {
|
|||||||
|
|
||||||
const mentions = wrapped.map((item) => '!' + item.channel.name);
|
const mentions = wrapped.map((item) => '!' + item.channel.name);
|
||||||
|
|
||||||
|
SuggestionStore.clearSuggestions(suggestionId);
|
||||||
SuggestionStore.addSuggestions(suggestionId, mentions, wrapped, ChannelMentionSuggestion, captured[2]);
|
SuggestionStore.addSuggestions(suggestionId, mentions, wrapped, ChannelMentionSuggestion, captured[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ export default class EmoticonProvider {
|
|||||||
const terms = matched.map((emoticon) => ':' + emoticon.name + ':');
|
const terms = matched.map((emoticon) => ':' + emoticon.name + ':');
|
||||||
|
|
||||||
if (terms.length > 0) {
|
if (terms.length > 0) {
|
||||||
|
SuggestionStore.clearSuggestions(suggestionId);
|
||||||
SuggestionStore.addSuggestions(suggestionId, terms, matched, EmoticonSuggestion, text);
|
SuggestionStore.addSuggestions(suggestionId, terms, matched, EmoticonSuggestion, text);
|
||||||
|
|
||||||
hasSuggestions = true;
|
hasSuggestions = true;
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export default class SearchChannelProvider {
|
|||||||
privateChannels.sort((a, b) => a.name.localeCompare(b.name));
|
privateChannels.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
const privateChannelNames = privateChannels.map((channel) => channel.name);
|
const privateChannelNames = privateChannels.map((channel) => channel.name);
|
||||||
|
|
||||||
|
SuggestionStore.clearSuggestions(suggestionId);
|
||||||
SuggestionStore.addSuggestions(suggestionId, publicChannelNames, publicChannels, SearchChannelSuggestion, channelPrefix);
|
SuggestionStore.addSuggestions(suggestionId, publicChannelNames, publicChannels, SearchChannelSuggestion, channelPrefix);
|
||||||
SuggestionStore.addSuggestions(suggestionId, privateChannelNames, privateChannels, SearchChannelSuggestion, channelPrefix);
|
SuggestionStore.addSuggestions(suggestionId, privateChannelNames, privateChannels, SearchChannelSuggestion, channelPrefix);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
import React from 'react';
|
import Suggestion from './suggestion.jsx';
|
||||||
|
|
||||||
import ChannelStore from 'stores/channel_store.jsx';
|
import ChannelStore from 'stores/channel_store.jsx';
|
||||||
import SuggestionStore from 'stores/suggestion_store.jsx';
|
|
||||||
import Suggestion from './suggestion.jsx';
|
import {autocompleteUsersInTeam} from 'actions/user_actions.jsx';
|
||||||
import Constants from 'utils/constants.jsx';
|
|
||||||
import StatusIcon from 'components/status_icon.jsx';
|
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
||||||
|
import {Constants, ActionTypes} from 'utils/constants.jsx';
|
||||||
import * as Utils from 'utils/utils.jsx';
|
import * as Utils from 'utils/utils.jsx';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
class SwitchChannelSuggestion extends Suggestion {
|
class SwitchChannelSuggestion extends Suggestion {
|
||||||
render() {
|
render() {
|
||||||
const {item, isSelection} = this.props;
|
const {item, isSelection} = this.props;
|
||||||
@@ -31,8 +34,6 @@ class SwitchChannelSuggestion extends Suggestion {
|
|||||||
icon = <div className='status'><i className='fa fa-globe'/></div>;
|
icon = <div className='status'><i className='fa fa-globe'/></div>;
|
||||||
} else if (item.type === Constants.PRIVATE_CHANNEL) {
|
} else if (item.type === Constants.PRIVATE_CHANNEL) {
|
||||||
icon = <div className='status'><i className='fa fa-lock'/></div>;
|
icon = <div className='status'><i className='fa fa-lock'/></div>;
|
||||||
} else {
|
|
||||||
icon = <StatusIcon status={item.status}/>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -48,46 +49,72 @@ class SwitchChannelSuggestion extends Suggestion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class SwitchChannelProvider {
|
export default class SwitchChannelProvider {
|
||||||
|
constructor() {
|
||||||
|
this.timeoutId = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
clearTimeout(this.timeoutId);
|
||||||
|
}
|
||||||
|
|
||||||
handlePretextChanged(suggestionId, channelPrefix) {
|
handlePretextChanged(suggestionId, channelPrefix) {
|
||||||
if (channelPrefix) {
|
if (channelPrefix) {
|
||||||
const allChannels = ChannelStore.getAll();
|
const allChannels = ChannelStore.getAll();
|
||||||
const channels = [];
|
const channels = [];
|
||||||
|
|
||||||
for (const id of Object.keys(allChannels)) {
|
function autocomplete() {
|
||||||
const channel = allChannels[id];
|
autocompleteUsersInTeam(
|
||||||
if (channel.display_name.toLowerCase().startsWith(channelPrefix.toLowerCase())) {
|
channelPrefix,
|
||||||
channels.push(channel);
|
(data) => {
|
||||||
}
|
const users = data.in_team;
|
||||||
|
|
||||||
// TODO: Fix with auto-complete refactor
|
for (const id of Object.keys(allChannels)) {
|
||||||
/*else if (channel.type === Constants.DM_CHANNEL && Utils.getDirectTeammate(channel.id).username.startsWith(channelPrefix.toLowerCase())) {
|
const channel = allChannels[id];
|
||||||
// New channel to not modify existing channel
|
if (channel.display_name.toLowerCase().startsWith(channelPrefix.toLowerCase())) {
|
||||||
const otherUser = Utils.getDirectTeammate(channel.id);
|
channels.push(channel);
|
||||||
const newChannel = {
|
}
|
||||||
display_name: otherUser.username,
|
}
|
||||||
name: otherUser.username + ' ' + Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)'),
|
|
||||||
type: Constants.DM_CHANNEL,
|
for (let i = 0; i < users.length; i++) {
|
||||||
status: UserStore.getStatus(otherUser.id) || 'offline'
|
const user = users[i];
|
||||||
};
|
const newChannel = {
|
||||||
channels.push(newChannel);
|
display_name: user.username,
|
||||||
}*/
|
name: user.username + ' ' + Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)'),
|
||||||
|
type: Constants.DM_CHANNEL
|
||||||
|
};
|
||||||
|
channels.push(newChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
channels.sort((a, b) => {
|
||||||
|
if (a.display_name === b.display_name) {
|
||||||
|
if (a.type !== Constants.DM_CHANNEL && b.type === Constants.DM_CHANNEL) {
|
||||||
|
return -1;
|
||||||
|
} else if (a.type === Constants.DM_CHANNEL && b.type !== Constants.DM_CHANNEL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return a.name.localeCompare(b.name);
|
||||||
|
}
|
||||||
|
return a.display_name.localeCompare(b.display_name);
|
||||||
|
});
|
||||||
|
|
||||||
|
const channelNames = channels.map((channel) => channel.name);
|
||||||
|
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
|
||||||
|
id: suggestionId,
|
||||||
|
matchedPretext: channelPrefix,
|
||||||
|
terms: channelNames,
|
||||||
|
items: channels,
|
||||||
|
component: SwitchChannelSuggestion
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
channels.sort((a, b) => {
|
this.timeoutId = setTimeout(
|
||||||
if (a.display_name === b.display_name) {
|
autocomplete.bind(this),
|
||||||
if (a.type !== Constants.DM_CHANNEL && b.type === Constants.DM_CHANNEL) {
|
Constants.AUTOCOMPLETE_TIMEOUT
|
||||||
return -1;
|
);
|
||||||
} else if (a.type === Constants.DM_CHANNEL && b.type !== Constants.DM_CHANNEL) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
}
|
|
||||||
return a.display_name.localeCompare(b.display_name);
|
|
||||||
});
|
|
||||||
|
|
||||||
const channelNames = channels.map((channel) => channel.name);
|
|
||||||
|
|
||||||
SuggestionStore.addSuggestions(suggestionId, channelNames, channels, SwitchChannelSuggestion, channelPrefix);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user