From 87830f99e7e47f19ce9368cca93b66a8c1c34517 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 5 Feb 2017 15:25:55 +0100 Subject: [PATCH] Fix #552 - Replace image links with image icons in status text in the UI --- .../components/components/status_content.jsx | 3 +++ app/assets/stylesheets/components.scss | 8 ++++++++ app/views/api/v1/statuses/_media.rabl | 1 + app/views/api/v1/statuses/show.rabl | 10 +++++----- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/components/components/status_content.jsx b/app/assets/javascripts/components/components/status_content.jsx index 81c1048607..9263a76f55 100644 --- a/app/assets/javascripts/components/components/status_content.jsx +++ b/app/assets/javascripts/components/components/status_content.jsx @@ -42,11 +42,14 @@ const StatusContent = React.createClass({ for (var i = 0; i < links.length; ++i) { let link = links[i]; let mention = this.props.status.get('mentions').find(item => link.href === item.get('url')); + let media = this.props.status.get('media_attachments').find(item => link.href === item.get('text_url') || link.href === item.get('remote_url')); if (mention) { link.addEventListener('click', this.onMentionClick.bind(this, mention), false); } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) { link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false); + } else if (media) { + link.innerHTML = ''; } else { link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener'); diff --git a/app/assets/stylesheets/components.scss b/app/assets/stylesheets/components.scss index ca0ec0cece..85d34c5312 100644 --- a/app/assets/stylesheets/components.scss +++ b/app/assets/stylesheets/components.scss @@ -125,6 +125,10 @@ &:hover { text-decoration: underline; + + .fa { + color: lighten($color1, 40%); + } } &.mention { @@ -136,6 +140,10 @@ } } } + + .fa { + color: lighten($color1, 30%); + } } .status__content__spoiler-link { diff --git a/app/views/api/v1/statuses/_media.rabl b/app/views/api/v1/statuses/_media.rabl index 5c6be1ce77..2f56c6d07d 100644 --- a/app/views/api/v1/statuses/_media.rabl +++ b/app/views/api/v1/statuses/_media.rabl @@ -2,3 +2,4 @@ attributes :id, :remote_url, :type node(:url) { |media| full_asset_url(media.file.url(:original)) } node(:preview_url) { |media| full_asset_url(media.file.url(:small)) } +node(:text_url) { |media| media.local? ? medium_url(media) : nil } diff --git a/app/views/api/v1/statuses/show.rabl b/app/views/api/v1/statuses/show.rabl index 1b4651cdd9..41e8983eff 100644 --- a/app/views/api/v1/statuses/show.rabl +++ b/app/views/api/v1/statuses/show.rabl @@ -2,12 +2,12 @@ object @status extends 'api/v1/statuses/_show' -node(:favourited, if: proc { !current_account.nil? }) { |status| defined?(@favourites_map) ? !!@favourites_map[status.id] : current_account.favourited?(status) } -node(:reblogged, if: proc { !current_account.nil? }) { |status| defined?(@reblogs_map) ? !!@reblogs_map[status.id] : current_account.reblogged?(status) } +node(:favourited, if: proc { !current_account.nil? }) { |status| defined?(@favourites_map) ? @favourites_map[status.id] : current_account.favourited?(status) } +node(:reblogged, if: proc { !current_account.nil? }) { |status| defined?(@reblogs_map) ? @reblogs_map[status.id] : current_account.reblogged?(status) } -child :reblog => :reblog do +child reblog: :reblog do extends 'api/v1/statuses/_show' - node(:favourited, if: proc { !current_account.nil? }) { |status| defined?(@favourites_map) ? !!@favourites_map[status.id] : current_account.favourited?(status) } - node(:reblogged, if: proc { !current_account.nil? }) { |status| defined?(@reblogs_map) ? !!@reblogs_map[status.id] : current_account.reblogged?(status) } + node(:favourited, if: proc { !current_account.nil? }) { |status| defined?(@favourites_map) ? @favourites_map[status.id] : current_account.favourited?(status) } + node(:reblogged, if: proc { !current_account.nil? }) { |status| defined?(@reblogs_map) ? @reblogs_map[status.id] : current_account.reblogged?(status) } end