From 8f8769aab58f82e9cd364aa0fb416dfe183fffc2 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Thu, 8 Dec 2011 18:22:27 -0800 Subject: [PATCH] basic NSFW filtering for authors who say their post is nsfw --- app/helpers/stream_element_helper.rb | 8 ++++++++ app/models/status_message.rb | 5 +++++ app/views/shared/_stream_element.html.haml | 16 +++++++++------- .../status_messages/_status_message.html.haml | 1 - config/locales/diaspora/en.yml | 2 ++ public/javascripts/stream.js | 11 +++++++++++ public/stylesheets/sass/application.sass | 10 ++++++++++ 7 files changed, 45 insertions(+), 8 deletions(-) diff --git a/app/helpers/stream_element_helper.rb b/app/helpers/stream_element_helper.rb index f79c5cacb..59abd9968 100644 --- a/app/helpers/stream_element_helper.rb +++ b/app/helpers/stream_element_helper.rb @@ -16,4 +16,12 @@ module StreamElementHelper link_to image_tag('deletelabel.png'), share_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete remove_post control_icon vis_hide", :title => t('.hide_and_mute') end end + + def nsfw_sheild(post) + if post.respond_to?(:nsfw?) && post.nsfw? + content_tag(:div, :class => 'shield') do + I18n.translate('shared.stream_element.nsfw', :link => link_to(I18n.translate('shared.stream_element.show'), '#')).html_safe + end + end + end end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index dd32b6cc0..bc99ae62c 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -63,9 +63,14 @@ class StatusMessage < Post def raw_message read_attribute(:text) end + def raw_message=(text) write_attribute(:text, text) end + + def nsfw? + self.raw_message.include?('#nsfw') + end def formatted_message(opts={}) return self.raw_message unless self.raw_message diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index db6e7468a..6f9467bb3 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -23,7 +23,7 @@ .sm_body = person_image_link(post.author, :size => :thumb_small) .content - %div.post_initial_info + .post_initial_info %span.from = person_link(post.author, :class => 'hovercardable') %time.time.timeago{:datetime => post.created_at, :integer => time_for_sort(post).to_i} @@ -33,12 +33,14 @@ %span.timeago = link_to(how_long_ago(post), post_path(post)) - - if post.activity_streams? - = link_to image_tag(post.image_url, 'data-small-photo' => post.image_url, 'data-full-photo' => post.image_url, :class => 'stream-photo'), post.object_url, :class => "stream-photo-link" - - elsif reshare?(post) - = render 'reshares/reshare', :reshare => post, :post => post.root - - else - = render 'status_messages/status_message', :post => post, :photos => post.photos + .post-content + = nsfw_sheild(post) + - if post.activity_streams? + = link_to image_tag(post.image_url, 'data-small-photo' => post.image_url, 'data-full-photo' => post.image_url, :class => 'stream-photo'), post.object_url, :class => "stream-photo-link" + - elsif reshare?(post) + = render 'reshares/reshare', :reshare => post, :post => post.root + - else + = render 'status_messages/status_message', :post => post, :photos => post.photos .info %span.via diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index a250b1f5a..7a0842cbe 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -2,7 +2,6 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - - if photos.size > 0 .photo_attachments .big_stream_photo diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 6bd15c7fd..c9d17ecaf 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -811,6 +811,8 @@ en: unlike: "Unlike" dislike: "Dislike" shared_with: "Shared with: %{aspect_names}" + nsfw: "This post has been flagged as NSFW by its author. %{link}" + show: "show" footer: logged_in_as: "logged in as %{name}" your_aspects: "your aspects" diff --git a/public/javascripts/stream.js b/public/javascripts/stream.js index 47bcd9320..d1d5ee048 100644 --- a/public/javascripts/stream.js +++ b/public/javascripts/stream.js @@ -5,6 +5,7 @@ var Stream = { selector: "#main_stream", + nsfw_links: ".shield a", initialize: function() { Diaspora.page.directionDetector.updateBinds(); @@ -13,6 +14,8 @@ var Stream = { }, initializeLives: function(){ + Stream.setUpNsfwLinks(); + // reshare button action $(".reshare_button", this.selector).live("click", function(evt) { evt.preventDefault(); @@ -24,6 +27,14 @@ var Stream = { box.toggle(); } }); + + }, + + setUpNsfwLinks:function(){ + $(this.nsfw_links).click(function(e){ + e.preventDefault(); + $(this).parent().fadeOut(); + }); }, setUpAudioLinks: function() { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 43b1767f0..0b9116ae2 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -3492,3 +3492,13 @@ a.toggle_selector &:hover @include opacity(1) +.post-content + :position relative + +.shield + :z-index 3 + :background-color #eee + :position absolute + :width 100% + :height 100% + :padding 5px