PLT-4200/3708 Fixed outside team DM switching, allowed switching to uncreated DMs (#4111)
* Fixed outside team DM switching, allowed switching to uncreated DMs * Update channel_switch_modal.jsx
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
2dd666cb8a
Коммит
38c34017a3
@@ -27,14 +27,30 @@ 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.handleDmUserChange = this.handleDmUserChange.bind(this);
|
||||||
this.suggestionProviders = [new SwitchChannelProvider()];
|
this.suggestionProviders = [new SwitchChannelProvider()];
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
dmUsers: UserStore.getDirectProfiles(),
|
||||||
text: '',
|
text: '',
|
||||||
error: ''
|
error: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
UserStore.addDmListChangeListener(this.handleDmUserChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
UserStore.removeDmListChangeListener(this.handleDmUserChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDmUserChange() {
|
||||||
|
this.setState({
|
||||||
|
dmUsers: UserStore.getDirectProfiles()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.props.show && !prevProps.show) {
|
if (this.props.show && !prevProps.show) {
|
||||||
const textbox = this.refs.search.getTextbox();
|
const textbox = this.refs.search.getTextbox();
|
||||||
@@ -83,7 +99,25 @@ export default class SwitchChannelModal extends React.Component {
|
|||||||
|
|
||||||
if (name.indexOf(Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)')) > 0) {
|
if (name.indexOf(Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)')) > 0) {
|
||||||
const dmUsername = name.substr(0, name.indexOf(Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)')) - 1);
|
const dmUsername = name.substr(0, name.indexOf(Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)')) - 1);
|
||||||
channel = ChannelStore.getByName(Utils.getDirectChannelNameByUsername(dmUsername, UserStore.getCurrentUser().username).trim());
|
let user = null;
|
||||||
|
for (const id in this.state.dmUsers) {
|
||||||
|
if (this.state.dmUsers[id].username === dmUsername) {
|
||||||
|
user = this.state.dmUsers[id];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
Utils.openDirectChannelToUser(
|
||||||
|
user,
|
||||||
|
(ch) => {
|
||||||
|
channel = ch;
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
channel = null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
channel = ChannelStore.getByName(this.state.text.trim());
|
channel = ChannelStore.getByName(this.state.text.trim());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1032,13 +1032,6 @@ export function getDirectChannelName(id, otherId) {
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDirectChannelNameByUsername(username, otherUsername) {
|
|
||||||
const id = UserStore.getProfileByUsername(username).id;
|
|
||||||
const otherId = UserStore.getProfileByUsername(otherUsername).id;
|
|
||||||
|
|
||||||
return getDirectChannelName(id, otherId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to get the id of the other user from a DM channel
|
// Used to get the id of the other user from a DM channel
|
||||||
export function getUserIdFromChannelName(channel) {
|
export function getUserIdFromChannelName(channel) {
|
||||||
var ids = channel.name.split('__');
|
var ids = channel.name.split('__');
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user