PLT-2640 Added searching users by additional field when autocompleting @mentions (#3412)
* Added the ability to search users by their first/last name or nickname when using @mentions * Changed @mention autocomplete to display a user's nickname
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
76c6505e7f
Коммит
734818790f
@@ -16,12 +16,13 @@ const MaxUserSuggestions = 40;
|
|||||||
|
|
||||||
class AtMentionSuggestion extends Suggestion {
|
class AtMentionSuggestion extends Suggestion {
|
||||||
render() {
|
render() {
|
||||||
const {item, isSelection} = this.props;
|
const isSelection = this.props.isSelection;
|
||||||
|
const user = this.props.item;
|
||||||
|
|
||||||
let username;
|
let username;
|
||||||
let description;
|
let description;
|
||||||
let icon;
|
let icon;
|
||||||
if (item.username === 'all') {
|
if (user.username === 'all') {
|
||||||
username = 'all';
|
username = 'all';
|
||||||
description = (
|
description = (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
@@ -33,7 +34,7 @@ class AtMentionSuggestion extends Suggestion {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
icon = <i className='mention__image fa fa-users fa-2x'/>;
|
icon = <i className='mention__image fa fa-users fa-2x'/>;
|
||||||
} else if (item.username === 'channel') {
|
} else if (user.username === 'channel') {
|
||||||
username = 'channel';
|
username = 'channel';
|
||||||
description = (
|
description = (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
@@ -43,12 +44,20 @@ class AtMentionSuggestion extends Suggestion {
|
|||||||
);
|
);
|
||||||
icon = <i className='mention__image fa fa-users fa-2x'/>;
|
icon = <i className='mention__image fa fa-users fa-2x'/>;
|
||||||
} else {
|
} else {
|
||||||
username = item.username;
|
username = user.username;
|
||||||
description = Utils.getFullName(item);
|
|
||||||
|
if ((user.first_name || user.last_name) && user.nickname) {
|
||||||
|
description = ` - ${Utils.getFullName(user)} (${user.nickname})`;
|
||||||
|
} else if (user.nickname) {
|
||||||
|
description = ` - (${user.nickname})`;
|
||||||
|
} else if (user.first_name || user.last_name) {
|
||||||
|
description = ` - ${Utils.getFullName(user)}`;
|
||||||
|
}
|
||||||
|
|
||||||
icon = (
|
icon = (
|
||||||
<img
|
<img
|
||||||
className='mention__image'
|
className='mention__image'
|
||||||
src={Client.getUsersRoute() + '/' + item.id + '/image?time=' + item.update_at}
|
src={Client.getUsersRoute() + '/' + user.id + '/image?time=' + user.update_at}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -81,17 +90,25 @@ class AtMentionSuggestion extends Suggestion {
|
|||||||
|
|
||||||
export default class AtMentionProvider {
|
export default class AtMentionProvider {
|
||||||
handlePretextChanged(suggestionId, pretext) {
|
handlePretextChanged(suggestionId, pretext) {
|
||||||
const captured = (/@([a-z0-9\-\._]*)$/i).exec(pretext);
|
const captured = (/@([a-z0-9\-\._]*)$/i).exec(pretext.toLowerCase());
|
||||||
if (captured) {
|
if (captured) {
|
||||||
const usernamePrefix = captured[1];
|
const prefix = captured[1];
|
||||||
|
|
||||||
const users = UserStore.getActiveOnlyProfiles(true);
|
const users = UserStore.getActiveOnlyProfiles(true);
|
||||||
let filtered = [];
|
|
||||||
|
const filtered = [];
|
||||||
|
|
||||||
for (const id of Object.keys(users)) {
|
for (const id of Object.keys(users)) {
|
||||||
const user = users[id];
|
const user = users[id];
|
||||||
|
|
||||||
if (user.username.startsWith(usernamePrefix) && user.delete_at <= 0) {
|
if (user.delete_at > 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.username.startsWith(prefix) ||
|
||||||
|
(user.first_name && user.first_name.toLowerCase().startsWith(prefix)) ||
|
||||||
|
(user.last_name && user.last_name.toLowerCase().startsWith(prefix)) ||
|
||||||
|
(user.nickname && user.nickname.toLowerCase().startsWith(prefix))) {
|
||||||
filtered.push(user);
|
filtered.push(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,15 +119,26 @@ export default class AtMentionProvider {
|
|||||||
|
|
||||||
if (!pretext.startsWith('/msg')) {
|
if (!pretext.startsWith('/msg')) {
|
||||||
// add dummy users to represent the @channel and @all special mentions when not using the /msg command
|
// add dummy users to represent the @channel and @all special mentions when not using the /msg command
|
||||||
if ('channel'.startsWith(usernamePrefix)) {
|
if ('channel'.startsWith(prefix)) {
|
||||||
filtered.push({username: 'channel'});
|
filtered.push({username: 'channel'});
|
||||||
}
|
}
|
||||||
if ('all'.startsWith(usernamePrefix)) {
|
if ('all'.startsWith(prefix)) {
|
||||||
filtered.push({username: 'all'});
|
filtered.push({username: 'all'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filtered = filtered.sort((a, b) => a.username.localeCompare(b.username));
|
filtered.sort((a, b) => {
|
||||||
|
const aPrefix = a.username.startsWith(prefix);
|
||||||
|
const bPrefix = b.username.startsWith(prefix);
|
||||||
|
|
||||||
|
if (aPrefix === bPrefix) {
|
||||||
|
return a.username.localeCompare(b.username);
|
||||||
|
} else if (aPrefix) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
const mentions = filtered.map((user) => '@' + user.username);
|
const mentions = filtered.map((user) => '@' + user.username);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
|
|
||||||
.mention__fullname {
|
.mention__fullname {
|
||||||
@include opacity(.5);
|
@include opacity(.5);
|
||||||
padding-left: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.mention--highlight {
|
.mention--highlight {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user