DG IZ reshare retractions is WIP
This commit is contained in:
parent
d1bbbdbc4c
commit
f3a515eef1
17 changed files with 153 additions and 39 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ class Reshare < Post
|
|||
self.public = true
|
||||
end
|
||||
|
||||
|
||||
delegate :photos, :text, :comments, :to => :root
|
||||
private
|
||||
|
||||
def root_must_be_public
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
25
app/views/reshares/_reshare.haml
Normal file
25
app/views/reshares/_reshare.haml
Normal file
|
|
@ -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
|
||||
|
|
@ -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)}
|
||||
|
|
|
|||
|
|
@ -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}?"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue