diff options
Diffstat (limited to 'web/react/components')
-rw-r--r-- | web/react/components/post_body.jsx | 14 | ||||
-rw-r--r-- | web/react/components/suggestion/emoticon_provider.jsx | 23 |
2 files changed, 31 insertions, 6 deletions
diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx index 296b9e7d7..35a7727e9 100644 --- a/web/react/components/post_body.jsx +++ b/web/react/components/post_body.jsx @@ -309,7 +309,15 @@ export default class PostBody extends React.Component { let apostrophe = ''; let name = '...'; if (profile != null) { - if (profile.username.slice(-1) === 's') { + let username = profile.username; + if (parentPost.props && + parentPost.props.from_webhook && + parentPost.props.override_username && + global.window.mm_config.EnablePostUsernameOverride === 'true') { + username = parentPost.props.override_username; + } + + if (username.slice(-1) === 's') { apostrophe = '\''; } else { apostrophe = '\'s'; @@ -317,9 +325,9 @@ export default class PostBody extends React.Component { name = ( <a className='theme' - onClick={Utils.searchForTerm.bind(null, profile.username)} + onClick={Utils.searchForTerm.bind(null, username)} > - {profile.username} + {username} </a> ); } diff --git a/web/react/components/suggestion/emoticon_provider.jsx b/web/react/components/suggestion/emoticon_provider.jsx index 7dcb86442..fd470cf21 100644 --- a/web/react/components/suggestion/emoticon_provider.jsx +++ b/web/react/components/suggestion/emoticon_provider.jsx @@ -51,23 +51,40 @@ export default class EmoticonProvider { const text = captured[1]; const partialName = captured[2]; - const terms = []; const names = []; for (const emoticon of Emoticons.emoticonMap.keys()) { if (emoticon.indexOf(partialName) !== -1) { - terms.push(':' + emoticon + ':'); names.push(emoticon); - if (terms.length >= MAX_EMOTICON_SUGGESTIONS) { + if (names.length >= MAX_EMOTICON_SUGGESTIONS) { break; } } } + // sort the emoticons so that emoticons starting with the entered text come first + names.sort((a, b) => { + const aPrefix = a.startsWith(partialName); + const bPrefix = b.startsWith(partialName); + + if (aPrefix === bPrefix) { + return a.localeCompare(b); + } else if (aPrefix) { + return -1; + } + + return 1; + }); + + const terms = names.map((name) => ':' + name + ':'); + if (terms.length > 0) { SuggestionStore.setMatchedPretext(suggestionId, text); SuggestionStore.addSuggestions(suggestionId, terms, names, EmoticonSuggestion); + + // force the selection to be cleared since the order of elements may have changed + SuggestionStore.clearSelection(suggestionId); } } } |