From 7b3180e5da4a6dab67e543f237b3a9b6de1bc72f Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 13 Jul 2011 13:37:36 -0700 Subject: [PATCH] user can retract a reshared post --- app/models/post.rb | 4 +-- app/models/reshare.rb | 14 ++++++++++ app/models/user.rb | 7 ++++- app/views/posts/show.html.haml | 2 +- app/views/reshares/_reshare.haml | 2 +- spec/models/reshare_spec.rb | 2 +- spec/models/user_spec.rb | 45 ++++++++++++++++++++++++++++++++ 7 files changed, 70 insertions(+), 6 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 0b43778ce..01da0e94b 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -24,8 +24,8 @@ 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 + has_many :reshares, :class_name => "Reshare", :foreign_key => :root_id + has_many :resharers, :class_name => 'Person', :through => :reshares, :source => :author belongs_to :author, :class_name => 'Person' diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 9fffce176..08853dee9 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -7,6 +7,20 @@ class Reshare < Post self.public = true end + def receive(user, person) + local_reshare = Reshare.where(:guid => self.guid).first + if local_reshare.root.author_id == user.person.id + local_reshare.root.reshares << local_reshare + + if user.contact_for(person) + local_reshare.receive(user, person) + end + + else + super(user, person) + end + end + private def root_must_be_public diff --git a/app/models/user.rb b/app/models/user.rb index 23621fed4..a1566f4d3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -237,7 +237,12 @@ class User < ActiveRecord::Base retraction = Retraction.for(target) end - mailman = Postzord::Dispatch.new(self, retraction) + opts = {} + if target.is_a?(Post) + opts[:additional_subscribers] = target.resharers + end + + mailman = Postzord::Dispatch.new(self, retraction, opts) mailman.post retraction.perform(self) diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index d06204d3a..716a1fd64 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -4,7 +4,7 @@ .span-20.append-2.prepend-2.last #main_stream.stream.status_message_show - = render 'shared/stream_element_shim', :post => @post, :commenting_disabled => defined?(@commenting_disabled) + = render 'shared/stream_element', :post => @post, :commenting_disabled => defined?(@commenting_disabled) %br %br %br diff --git a/app/views/reshares/_reshare.haml b/app/views/reshares/_reshare.haml index 456b3555c..2a71f683a 100644 --- a/app/views/reshares/_reshare.haml +++ b/app/views/reshares/_reshare.haml @@ -17,7 +17,7 @@ = 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) + - if defined?(current_user) && current_user && (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/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index cd4a87bc5..523f6cc78 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -20,7 +20,7 @@ describe Reshare do describe "#receive" do before do - @reshare = Factory.build(:reshare, :root => Factory.build(:status_message, :public => false)) + @reshare = Factory.create(:reshare, :root => Factory(:status_message, :author => bob.person, :public => true)) @root = @reshare.root @reshare.receive(@root.author.owner, @reshare.author) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b34d92e3d..7cc3944c4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -752,4 +752,49 @@ describe User do end end end + + describe '#retract' do + before do + @retraction = mock + end + + context "regular retractions" do + before do + Retraction.stub(:for).and_return(@retraction) + @retraction.stub(:perform) + + @post = Factory(:status_message, :author => bob.person, :public => true) + end + + it 'sends a retraction' do + dispatcher = mock + Postzord::Dispatch.should_receive(:new).with(bob, @retraction, anything()).and_return(dispatcher) + dispatcher.should_receive(:post) + + bob.retract(@post) + end + + it 'adds resharers of target post as additional subsctibers' do + person = Factory(:person) + reshare = Factory(:reshare, :root => @post, :author => person) + @post.reshares << reshare + + dispatcher = mock + Postzord::Dispatch.should_receive(:new).with(bob, @retraction, {:additional_subscribers => [person]}).and_return(dispatcher) + dispatcher.should_receive(:post) + + bob.retract(@post) + end + + it 'performs the retraction' do + + end + end + + context "relayable retractions" do + it 'sends a relayable retraction if the object is relayable' do + + end + end + end end