From 15af998d7bc1fe2f85f3a8a2eb799d872c99d37a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 15 Nov 2016 18:38:57 +0100 Subject: [PATCH] Support emojis in display name, bio --- .../components/components/display_name.jsx | 13 ++++++------- .../components/components/status_content.jsx | 8 ++------ app/assets/javascripts/components/emoji.jsx | 9 +++++++++ .../features/account/components/header.jsx | 11 +++++++---- app/assets/stylesheets/components.scss | 9 +++++++++ 5 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 app/assets/javascripts/components/emoji.jsx diff --git a/app/assets/javascripts/components/components/display_name.jsx b/app/assets/javascripts/components/components/display_name.jsx index a6e4ed9968..053b5290ce 100644 --- a/app/assets/javascripts/components/components/display_name.jsx +++ b/app/assets/javascripts/components/components/display_name.jsx @@ -1,5 +1,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import PureRenderMixin from 'react-addons-pure-render-mixin'; +import escapeTextContentForBrowser from 'react/lib/escapeTextContentForBrowser'; +import emojify from '../emoji'; const DisplayName = React.createClass({ @@ -10,15 +12,12 @@ const DisplayName = React.createClass({ mixins: [PureRenderMixin], render () { - let displayName = this.props.account.get('display_name'); - - if (displayName.length === 0) { - displayName = this.props.account.get('username'); - } + const displayName = this.props.account.get('display_name').length === 0 ? this.props.account.get('username') : this.props.account.get('display_name'); + const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) }; return ( - - {displayName} @{this.props.account.get('acct')} + + @{this.props.account.get('acct')} ); } diff --git a/app/assets/javascripts/components/components/status_content.jsx b/app/assets/javascripts/components/components/status_content.jsx index 583f4cec6d..eeb43a12c8 100644 --- a/app/assets/javascripts/components/components/status_content.jsx +++ b/app/assets/javascripts/components/components/status_content.jsx @@ -1,10 +1,6 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import PureRenderMixin from 'react-addons-pure-render-mixin'; -import emojione from 'emojione'; - -emojione.imageType = 'png'; -emojione.sprites = false; -emojione.imagePathPNG = '/emoji/'; +import emojify from '../emoji'; const StatusContent = React.createClass({ @@ -61,7 +57,7 @@ const StatusContent = React.createClass({ }, render () { - const content = { __html: emojione.unicodeToImage(this.props.status.get('content')) }; + const content = { __html: emojify(this.props.status.get('content')) }; return
; }, diff --git a/app/assets/javascripts/components/emoji.jsx b/app/assets/javascripts/components/emoji.jsx new file mode 100644 index 0000000000..a06c759531 --- /dev/null +++ b/app/assets/javascripts/components/emoji.jsx @@ -0,0 +1,9 @@ +import emojione from 'emojione'; + +emojione.imageType = 'png'; +emojione.sprites = false; +emojione.imagePathPNG = '/emoji/'; + +export default function emojify(text) { + return emojione.unicodeToImage(text); +}; diff --git a/app/assets/javascripts/components/features/account/components/header.jsx b/app/assets/javascripts/components/features/account/components/header.jsx index 062f4a0f2c..7a086c99a3 100644 --- a/app/assets/javascripts/components/features/account/components/header.jsx +++ b/app/assets/javascripts/components/features/account/components/header.jsx @@ -1,5 +1,7 @@ -import PureRenderMixin from 'react-addons-pure-render-mixin'; +import PureRenderMixin from 'react-addons-pure-render-mixin'; import ImmutablePropTypes from 'react-immutable-proptypes'; +import emojify from '../../../emoji'; +import escapeTextContentForBrowser from 'react/lib/escapeTextContentForBrowser'; const Header = React.createClass({ @@ -14,7 +16,7 @@ const Header = React.createClass({ const { account, me } = this.props; let displayName = account.get('display_name'); - let info = ''; + let info = ''; if (displayName.length === 0) { displayName = account.get('username'); @@ -24,7 +26,8 @@ const Header = React.createClass({ info = Follows you } - const content = { __html: account.get('note') }; + const content = { __html: emojify(account.get('note')) }; + const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) }; return (
@@ -34,7 +37,7 @@ const Header = React.createClass({
- {displayName} + @{account.get('acct')} diff --git a/app/assets/stylesheets/components.scss b/app/assets/stylesheets/components.scss index 2cd58bb2bc..c15a827a40 100644 --- a/app/assets/stylesheets/components.scss +++ b/app/assets/stylesheets/components.scss @@ -76,6 +76,8 @@ font-size: inherit; vertical-align: middle; margin: -.2ex .15em .2ex; + width: 16px; + height: 16px; img { width: auto; @@ -166,6 +168,13 @@ } } +.account__header__display-name { + .emojione { + width: 25px; + height: 25px; + } +} + .status__display-name, .status__relative-time, .detailed-status__display-name, .detailed-status__datetime, .account__display-name { text-decoration: none; }