From f3a515eef165095b79de85418e33eb968e65e59a Mon Sep 17 00:00:00 2001 From: danielgrippi <danielgrippi@gmail.com> Date: Tue, 12 Jul 2011 19:03:35 -0700 Subject: [PATCH] DG IZ reshare retractions is WIP --- app/controllers/reshares_controller.rb | 1 + app/helpers/stream_helper.rb | 4 ++ app/models/post.rb | 3 ++ app/models/reshare.rb | 2 - app/models/user.rb | 3 +- app/views/reshares/_reshare.haml | 25 +++++++++ app/views/shared/_stream.haml | 2 +- app/views/shared/_stream_element.html.haml | 15 +++--- app/views/shared/_stream_element_shim.haml | 4 -- features/repost.feature | 52 +++++++++++++++++-- features/step_definitions/custom_web_steps.rb | 4 ++ features/step_definitions/posts_steps.rb | 3 ++ lib/postzord/dispatch.rb | 5 +- public/stylesheets/sass/application.sass | 30 ++++++----- spec/controllers/reshares_controller_spec.rb | 5 ++ spec/lib/postzord/dispatch_spec.rb | 18 +++++-- spec/models/reshare_spec.rb | 16 ++++++ 17 files changed, 153 insertions(+), 39 deletions(-) create mode 100644 app/views/reshares/_reshare.haml delete mode 100644 app/views/shared/_stream_element_shim.haml diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index d28a0c0a5f..9520715c70 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -6,6 +6,7 @@ class ResharesController < ApplicationController @reshare = current_user.build_post(:reshare, :root_id => params[:root_id]) if @reshare.save! current_user.add_to_streams(@reshare, current_user.aspects) + current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author) end respond_with @reshare diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index 566a92d541..55d006cd60 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -28,4 +28,8 @@ module StreamHelper def comments_expanded false end + + def reshare?(post) + (defined?(post.model) && post.model.is_a?(Reshare)) || post.instance_of?(Reshare) + end end diff --git a/app/models/post.rb b/app/models/post.rb index 45dec7028b..0b43778ce5 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -24,6 +24,9 @@ class Post < ActiveRecord::Base has_many :contacts, :through => :post_visibilities has_many :mentions, :dependent => :destroy + has_many :reshares, :class_name => "Reshare" + has_many :resharers, :through => :reshares, :foreign_key => :root_id, :source => :author + belongs_to :author, :class_name => 'Person' def diaspora_handle diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 05f29367ff..9fffce1766 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -7,8 +7,6 @@ class Reshare < Post self.public = true end - - delegate :photos, :text, :comments, :to => :root private def root_must_be_public diff --git a/app/models/user.rb b/app/models/user.rb index e6df4fe045..23621fed43 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -136,7 +136,8 @@ class User < ActiveRecord::Base end def dispatch_post(post, opts = {}) - mailman = Postzord::Dispatch.new(self, post) + additional_people = opts.delete(:additional_subscribers) + mailman = Postzord::Dispatch.new(self, post, :additional_subscribers => additional_people) mailman.post(opts) end diff --git a/app/views/reshares/_reshare.haml b/app/views/reshares/_reshare.haml new file mode 100644 index 0000000000..456b3555c3 --- /dev/null +++ b/app/views/reshares/_reshare.haml @@ -0,0 +1,25 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +.reshare + - if post + = person_image_link(post.author, :size => :thumb_small) + + .content + .right + = link_to "Show Original", post_path(post) + %span.from + = person_link(post.author, :class => "hovercardable") + + - 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" + - else + = render 'status_messages/status_message', :post => post, :photos => post.photos + - if (post.author_id != current_user.person.id) && (post.public?) && !reshare?(post) + %span.reshare_action + = link_to "Reshare", reshares_path(:root_id => post.id), :method => :post, :remote => true, :confirm => "Reshare: #{post.author.name} - #{post.text}?" + + - else + Original post deleted by author diff --git a/app/views/shared/_stream.haml b/app/views/shared/_stream.haml index 1d79fb636c..95ee72a0f5 100644 --- a/app/views/shared/_stream.haml +++ b/app/views/shared/_stream.haml @@ -3,7 +3,7 @@ -# the COPYRIGHT file. -= render :partial => 'shared/stream_element_shim', += render :partial => 'shared/stream_element', :collection => posts, :as => :post, :locals => { :commenting_disabled => defined?(@commenting_disabled)} diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 2e619e288e..a4a1f735fa 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -4,15 +4,13 @@ .stream_element{:id => post.guid} - if current_user && post.author.owner_id == current_user.id - - if reshare - .reshare_attribution - = "reshared by #{reshare.author.name}" .right.controls = link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete') - else .right.controls - = link_to image_tag('deletelabel.png'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete", :title => t('hide') + = link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete') + .undo_text.hidden = t('post_visibilites.update.post_hidden', :name => post.author.name) = link_to t('undo'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete" @@ -24,10 +22,7 @@ %span.from = person_link(post.author, :class => 'hovercardable') %time.time.timeago{:datetime => post.created_at, :integer => time_for_sort(post).to_i} - - if reshare - %span.reshared - = "reshared by" - = person_link(reshare.author, :class => "hovercardable") + %span.details – %span.timeago @@ -35,6 +30,8 @@ - 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 @@ -61,7 +58,7 @@ %span.like_action = like_action(post, current_user) - - unless(post.author_id == current_user.person.id) || (!post.public?) + - if (post.author_id != current_user.person.id) && (post.public?) && !reshare?(post) · %span.reshare_action = link_to "Reshare", reshares_path(:root_id => post.id), :method => :post, :remote => true, :confirm => "Reshare: #{post.author.name} - #{post.text}?" diff --git a/app/views/shared/_stream_element_shim.haml b/app/views/shared/_stream_element_shim.haml deleted file mode 100644 index 7a2512880a..0000000000 --- a/app/views/shared/_stream_element_shim.haml +++ /dev/null @@ -1,4 +0,0 @@ --if (defined?(post.model) && post.model.is_a?(Reshare)) || post.instance_of?(Reshare) - = render 'shared/stream_element', :post => post.root, :commenting_disabled => commenting_disabled, :reshare => post -- else - = render 'shared/stream_element', :post => post, :commenting_disabled => commenting_disabled, :reshare => nil diff --git a/features/repost.feature b/features/repost.feature index 7755577302..4dd29df780 100644 --- a/features/repost.feature +++ b/features/repost.feature @@ -34,11 +34,9 @@ Feature: public repost And I wait for the ajax to finish And I wait for 2 seconds - - And I am on "alice@alice.alice"'s page Then I should see "reshare this!" - Then I should see a ".reshared" + Then I should see a ".reshare" And I should see "Bob" Scenario: shows up on the aspects page @@ -49,9 +47,53 @@ Feature: public repost And I wait for the ajax to finish And I go to the home page - Then I should see a ".reshared" + Then I should see a ".reshare" And I follow "Your Aspects" Then I should see "reshare this!" - Then I should see a ".reshared" + Then I should see a ".reshare" And I should see "Bob" + Scenario: can be retracted + And "bob@bob.bob" has a public post with text "reshare this!" + And I sign in as "alice@alice.alice" + And I preemptively confirm the alert + And I follow "Reshare" + And I wait for the ajax to finish + + And I go to the home page + Then I should see a ".reshare" + And I follow "Your Aspects" + Then I should see "reshare this!" + Then I should see a ".reshare" + And I should see "Bob" + + And I go to the destroy user session page + And I sign in as "bob@bob.bob" + + And The user deletes their first post + + And I go to the destroy user session page + And I sign in as "alice@alice.alice" + + And I go to the home page + Then I should see "Original post deleted by author" + + Scenario: Keeps track of the number of reshares + And "bob@bob.bob" has a public post with text "reshare this!" + And I sign in as "alice@alice.alice" + And I preemptively confirm the alert + And I follow "Reshare" + And I wait for the ajax to finish + + And I go to the home page + Then I should see a ".reshare" + And I follow "Your Aspects" + Then I should see "reshare this!" + Then I should see a ".reshare" + And I should see "Bob" + + And I go to the destroy user session page + And I sign in as "bob@bob.bob" + And I should see "1 Reshare" + + Scenario: Can have text diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 63c0e9b346..8233da35e8 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -44,6 +44,10 @@ When /^I click to delete the first post$/ do page.execute_script('$(".stream_element").first().find(".stream_element_delete").first().click()') end +When /^I click to delete the ([\d])(nd|rd|st|th) post$/ do |number, stuff| + page.execute_script('$(".stream_element:nth-child('+ number +'").first().find(".stream_element_delete").first().click()') +end + When /^I click to delete the first comment$/ do page.execute_script('$(".comment.posted").first().find(".comment_delete").click()') end diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index d9879e72a3..94bf863df0 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -19,3 +19,6 @@ Given /^"([^"]*)" has a non public post with text "([^"]*)"$/ do |email, text| user.post(:status_message, :text => text, :public => false, :to => user.aspects) end +When /^The user deletes their first post$/ do + @me.posts.first.destroy +end diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 75ba6db1f3..cb99b3635f 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -3,7 +3,9 @@ # the COPYRIGHT file. class Postzord::Dispatch - def initialize(user, object) + + # @note Takes :additional_subscribers param to add to subscribers to dispatch to + def initialize(user, object, opts={}) unless object.respond_to? :to_diaspora_xml raise 'this object does not respond_to? to_diaspora xml. try including Diaspora::Webhooks into your object' end @@ -12,6 +14,7 @@ class Postzord::Dispatch @object = object @xml = @object.to_diaspora_xml @subscribers = @object.subscribers(@sender) + @subscribers = @subscribers | [*opts[:additional_subscribers]] if opts[:additional_subscribers] end def salmon diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index b02d1881e5..5a4b4ee1e1 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -475,6 +475,7 @@ ul.as-selections .from a :color $blue + .status_message_show .stream_element .content @@ -554,7 +555,8 @@ ul.as-selections ul.comments, ul.show_comments, -.likes_container +.likes_container, +.stream_element .reshare .avatar :width 30px @@ -589,18 +591,18 @@ ul.show_comments, :height 250px :width 400px - .content - :margin - :top 0px - :bottom -2px - :padding - :left 36px - :right 10px + .content + :margin + :top 0px + :bottom -2px + :padding + :left 36px + :right 10px - p - :margin - :bottom 0 - :top 0 + p + :margin + :bottom 0 + :top 0 .right :right 4px @@ -609,6 +611,10 @@ ul.show_comments, :position absolute :display inline +.stream_element .reshare + :padding 10px + :border 1px solid #eee + ul.show_comments :padding :bottom 6px diff --git a/spec/controllers/reshares_controller_spec.rb b/spec/controllers/reshares_controller_spec.rb index 23508cf864..5dbaaab7ab 100644 --- a/spec/controllers/reshares_controller_spec.rb +++ b/spec/controllers/reshares_controller_spec.rb @@ -29,6 +29,11 @@ describe ResharesController do bob.should_receive(:add_to_streams) post :create, :format => :js, :root_id => @post_id end + + it 'calls dispatch' do + bob.should_receive(:dispatch_post).with(anything, hash_including(:additional_subscribers)) + post :create, :format => :js, :root_id => @post_id + end end end end diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index 6991e8b931..da8181c54b 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -23,10 +23,20 @@ describe Postzord::Dispatch do zord.instance_variable_get(:@object).should == @sm end - it 'sets @subscribers from object' do - @sm.should_receive(:subscribers).and_return(@subscribers) - zord = Postzord::Dispatch.new(alice, @sm) - zord.instance_variable_get(:@subscribers).should == @subscribers + context 'setting @subscribers' do + it 'sets @subscribers from object' do + @sm.should_receive(:subscribers).and_return(@subscribers) + zord = Postzord::Dispatch.new(alice, @sm) + zord.instance_variable_get(:@subscribers).should == @subscribers + end + + it 'accepts additional subscribers from opts' do + new_person = Factory(:person) + + @sm.should_receive(:subscribers).and_return(@subscribers) + zord = Postzord::Dispatch.new(alice, @sm, :additional_subscribers => new_person) + zord.instance_variable_get(:@subscribers).should == @subscribers | [new_person] + end end it 'sets the @sender_person object' do diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index 7fcd620ae8..cd4a87bc59 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -17,4 +17,20 @@ describe Reshare do it 'forces public' do Factory(:reshare, :public => false).public.should be_true end + + describe "#receive" do + before do + @reshare = Factory.build(:reshare, :root => Factory.build(:status_message, :public => false)) + @root = @reshare.root + @reshare.receive(@root.author.owner, @reshare.author) + end + + it 'increments the reshare count' do + @root.resharers.count.should == 1 + end + + it 'adds the resharer to the re-sharers of the post' do + @root.resharers.should include(@reshare.author) + end + end end -- GitLab