From 23fc424b7aea139a0aff5cd347f46c81e50c2c56 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 7 Nov 2016 01:14:12 +0100 Subject: [PATCH] Account notes (bios) can now contain links. Character limit upped to 160 --- .../features/account/components/header.jsx | 4 +++- app/assets/stylesheets/components.scss | 23 +++++++++++++++++++ app/lib/formatter.rb | 15 +++++++++--- app/models/account.rb | 2 +- app/views/accounts/_header.html.haml | 2 +- app/views/api/v1/accounts/show.rabl | 3 ++- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/components/features/account/components/header.jsx b/app/assets/javascripts/components/features/account/components/header.jsx index d794a0aaf..39666bdc1 100644 --- a/app/assets/javascripts/components/features/account/components/header.jsx +++ b/app/assets/javascripts/components/features/account/components/header.jsx @@ -24,6 +24,8 @@ const Header = React.createClass({ info = Follows you } + const content = { __html: account.get('note') }; + return (
@@ -36,7 +38,7 @@ const Header = React.createClass({ @{account.get('acct')} -

{account.get('note')}

+
{info}
diff --git a/app/assets/stylesheets/components.scss b/app/assets/stylesheets/components.scss index 80e6cb5a8..37272e8e5 100644 --- a/app/assets/stylesheets/components.scss +++ b/app/assets/stylesheets/components.scss @@ -118,6 +118,29 @@ } } +.account__header__content { + word-wrap: break-word; + font-weight: 300; + overflow: hidden; + + p { + margin-bottom: 20px; + + &:last-child { + margin-bottom: 0; + } + } + + a { + color: inherit; + text-decoration: underline; + + &:hover { + text-decoration: none; + } + } +} + .status__display-name, .status__relative-time, .detailed-status__display-name, .detailed-status__datetime, .account__display-name { text-decoration: none; } diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 1ec77e56d..d7b100649 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -8,7 +8,7 @@ class Formatter include ActionView::Helpers::SanitizeHelper def format(status) - return reformat(status) unless status.local? + return reformat(status.content) unless status.local? html = status.text html = encode(html) @@ -20,8 +20,17 @@ class Formatter html.html_safe end - def reformat(status) - sanitize(status.content, tags: %w(a br p), attributes: %w(href rel)) + def reformat(html) + sanitize(html, tags: %w(a br p), attributes: %w(href rel)) + end + + def simplified_format(account) + return reformat(account.note) unless account.local? + + html = encode(account.note) + html = link_urls(html) + + html.html_safe end private diff --git a/app/models/account.rb b/app/models/account.rb index cb186b465..936095ffd 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -21,7 +21,7 @@ class Account < ApplicationRecord # Local user profile validations validates :display_name, length: { maximum: 30 }, if: 'local?' - validates :note, length: { maximum: 124 }, if: 'local?' + validates :note, length: { maximum: 160 }, if: 'local?' # Timelines has_many :stream_entries, inverse_of: :account, dependent: :destroy diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml index fb9abd691..ec2233b77 100644 --- a/app/views/accounts/_header.html.haml +++ b/app/views/accounts/_header.html.haml @@ -12,7 +12,7 @@ %small= "@#{@account.username}" .details .bio - %p= @account.note + .account__header__content= Formatter.instance.simplified_format(@account) .details-counters .counter{ class: active_nav_class(account_url(@account)) } diff --git a/app/views/api/v1/accounts/show.rabl b/app/views/api/v1/accounts/show.rabl index 0d9e268a1..623329059 100644 --- a/app/views/api/v1/accounts/show.rabl +++ b/app/views/api/v1/accounts/show.rabl @@ -1,7 +1,8 @@ object @account -attributes :id, :username, :acct, :display_name, :note +attributes :id, :username, :acct, :display_name +node(:note) { |account| Formatter.instance.simplified_format(account) } node(:url) { |account| TagManager.instance.url_for(account) } node(:avatar) { |account| full_asset_url(account.avatar.url(:large, false)) } node(:header) { |account| full_asset_url(account.header.url(:medium, false)) }