user can retract a reshared post

This commit is contained in:
danielgrippi 2011-07-13 13:37:36 -07:00 committed by Raphael Sofaer
parent f3a515eef1
commit 7b3180e5da
7 changed files with 70 additions and 6 deletions

View file

@ -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'

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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}?"

View file

@ -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

View file

@ -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