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])
|
@reshare = current_user.build_post(:reshare, :root_id => params[:root_id])
|
||||||
if @reshare.save!
|
if @reshare.save!
|
||||||
current_user.add_to_streams(@reshare, current_user.aspects)
|
current_user.add_to_streams(@reshare, current_user.aspects)
|
||||||
|
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with @reshare
|
respond_with @reshare
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,8 @@ module StreamHelper
|
||||||
def comments_expanded
|
def comments_expanded
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reshare?(post)
|
||||||
|
(defined?(post.model) && post.model.is_a?(Reshare)) || post.instance_of?(Reshare)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ class Post < ActiveRecord::Base
|
||||||
has_many :contacts, :through => :post_visibilities
|
has_many :contacts, :through => :post_visibilities
|
||||||
has_many :mentions, :dependent => :destroy
|
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'
|
belongs_to :author, :class_name => 'Person'
|
||||||
|
|
||||||
def diaspora_handle
|
def diaspora_handle
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ class Reshare < Post
|
||||||
self.public = true
|
self.public = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
delegate :photos, :text, :comments, :to => :root
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def root_must_be_public
|
def root_must_be_public
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,8 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def dispatch_post(post, opts = {})
|
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)
|
mailman.post(opts)
|
||||||
end
|
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.
|
-# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
= render :partial => 'shared/stream_element_shim',
|
= render :partial => 'shared/stream_element',
|
||||||
:collection => posts,
|
:collection => posts,
|
||||||
:as => :post,
|
:as => :post,
|
||||||
:locals => { :commenting_disabled => defined?(@commenting_disabled)}
|
:locals => { :commenting_disabled => defined?(@commenting_disabled)}
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,13 @@
|
||||||
|
|
||||||
.stream_element{:id => post.guid}
|
.stream_element{:id => post.guid}
|
||||||
- if current_user && post.author.owner_id == current_user.id
|
- if current_user && post.author.owner_id == current_user.id
|
||||||
- if reshare
|
|
||||||
.reshare_attribution
|
|
||||||
= "reshared by #{reshare.author.name}"
|
|
||||||
.right.controls
|
.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')
|
= 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
|
- else
|
||||||
.right.controls
|
.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
|
.undo_text.hidden
|
||||||
= t('post_visibilites.update.post_hidden', :name => post.author.name)
|
= 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"
|
= 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
|
%span.from
|
||||||
= person_link(post.author, :class => 'hovercardable')
|
= person_link(post.author, :class => 'hovercardable')
|
||||||
%time.time.timeago{:datetime => post.created_at, :integer => time_for_sort(post).to_i}
|
%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.details
|
||||||
–
|
–
|
||||||
%span.timeago
|
%span.timeago
|
||||||
|
|
@ -35,6 +30,8 @@
|
||||||
|
|
||||||
- if post.activity_streams?
|
- 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"
|
= 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
|
- else
|
||||||
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
||||||
|
|
||||||
|
|
@ -61,7 +58,7 @@
|
||||||
%span.like_action
|
%span.like_action
|
||||||
= like_action(post, current_user)
|
= 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
|
%span.reshare_action
|
||||||
= link_to "Reshare", reshares_path(:root_id => post.id), :method => :post, :remote => true, :confirm => "Reshare: #{post.author.name} - #{post.text}?"
|
= 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 the ajax to finish
|
||||||
And I wait for 2 seconds
|
And I wait for 2 seconds
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
And I am on "alice@alice.alice"'s page
|
And I am on "alice@alice.alice"'s page
|
||||||
Then I should see "reshare this!"
|
Then I should see "reshare this!"
|
||||||
Then I should see a ".reshared"
|
Then I should see a ".reshare"
|
||||||
And I should see "Bob"
|
And I should see "Bob"
|
||||||
|
|
||||||
Scenario: shows up on the aspects page
|
Scenario: shows up on the aspects page
|
||||||
|
|
@ -49,9 +47,53 @@ Feature: public repost
|
||||||
And I wait for the ajax to finish
|
And I wait for the ajax to finish
|
||||||
|
|
||||||
And I go to the home page
|
And I go to the home page
|
||||||
Then I should see a ".reshared"
|
Then I should see a ".reshare"
|
||||||
And I follow "Your Aspects"
|
And I follow "Your Aspects"
|
||||||
Then I should see "reshare this!"
|
Then I should see "reshare this!"
|
||||||
Then I should see a ".reshared"
|
Then I should see a ".reshare"
|
||||||
And I should see "Bob"
|
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()')
|
page.execute_script('$(".stream_element").first().find(".stream_element_delete").first().click()')
|
||||||
end
|
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
|
When /^I click to delete the first comment$/ do
|
||||||
page.execute_script('$(".comment.posted").first().find(".comment_delete").click()')
|
page.execute_script('$(".comment.posted").first().find(".comment_delete").click()')
|
||||||
end
|
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)
|
user.post(:status_message, :text => text, :public => false, :to => user.aspects)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When /^The user deletes their first post$/ do
|
||||||
|
@me.posts.first.destroy
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class Postzord::Dispatch
|
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
|
unless object.respond_to? :to_diaspora_xml
|
||||||
raise 'this object does not respond_to? to_diaspora xml. try including Diaspora::Webhooks into your object'
|
raise 'this object does not respond_to? to_diaspora xml. try including Diaspora::Webhooks into your object'
|
||||||
end
|
end
|
||||||
|
|
@ -12,6 +14,7 @@ class Postzord::Dispatch
|
||||||
@object = object
|
@object = object
|
||||||
@xml = @object.to_diaspora_xml
|
@xml = @object.to_diaspora_xml
|
||||||
@subscribers = @object.subscribers(@sender)
|
@subscribers = @object.subscribers(@sender)
|
||||||
|
@subscribers = @subscribers | [*opts[:additional_subscribers]] if opts[:additional_subscribers]
|
||||||
end
|
end
|
||||||
|
|
||||||
def salmon
|
def salmon
|
||||||
|
|
|
||||||
|
|
@ -475,6 +475,7 @@ ul.as-selections
|
||||||
.from
|
.from
|
||||||
a
|
a
|
||||||
:color $blue
|
:color $blue
|
||||||
|
|
||||||
.status_message_show
|
.status_message_show
|
||||||
.stream_element
|
.stream_element
|
||||||
.content
|
.content
|
||||||
|
|
@ -554,7 +555,8 @@ ul.as-selections
|
||||||
|
|
||||||
ul.comments,
|
ul.comments,
|
||||||
ul.show_comments,
|
ul.show_comments,
|
||||||
.likes_container
|
.likes_container,
|
||||||
|
.stream_element .reshare
|
||||||
|
|
||||||
.avatar
|
.avatar
|
||||||
:width 30px
|
:width 30px
|
||||||
|
|
@ -589,18 +591,18 @@ ul.show_comments,
|
||||||
:height 250px
|
:height 250px
|
||||||
:width 400px
|
:width 400px
|
||||||
|
|
||||||
.content
|
.content
|
||||||
:margin
|
:margin
|
||||||
:top 0px
|
:top 0px
|
||||||
:bottom -2px
|
:bottom -2px
|
||||||
:padding
|
:padding
|
||||||
:left 36px
|
:left 36px
|
||||||
:right 10px
|
:right 10px
|
||||||
|
|
||||||
p
|
p
|
||||||
:margin
|
:margin
|
||||||
:bottom 0
|
:bottom 0
|
||||||
:top 0
|
:top 0
|
||||||
|
|
||||||
.right
|
.right
|
||||||
:right 4px
|
:right 4px
|
||||||
|
|
@ -609,6 +611,10 @@ ul.show_comments,
|
||||||
:position absolute
|
:position absolute
|
||||||
:display inline
|
:display inline
|
||||||
|
|
||||||
|
.stream_element .reshare
|
||||||
|
:padding 10px
|
||||||
|
:border 1px solid #eee
|
||||||
|
|
||||||
ul.show_comments
|
ul.show_comments
|
||||||
:padding
|
:padding
|
||||||
:bottom 6px
|
:bottom 6px
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,11 @@ describe ResharesController do
|
||||||
bob.should_receive(:add_to_streams)
|
bob.should_receive(:add_to_streams)
|
||||||
post :create, :format => :js, :root_id => @post_id
|
post :create, :format => :js, :root_id => @post_id
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,20 @@ describe Postzord::Dispatch do
|
||||||
zord.instance_variable_get(:@object).should == @sm
|
zord.instance_variable_get(:@object).should == @sm
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets @subscribers from object' do
|
context 'setting @subscribers' do
|
||||||
@sm.should_receive(:subscribers).and_return(@subscribers)
|
it 'sets @subscribers from object' do
|
||||||
zord = Postzord::Dispatch.new(alice, @sm)
|
@sm.should_receive(:subscribers).and_return(@subscribers)
|
||||||
zord.instance_variable_get(:@subscribers).should == @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
|
end
|
||||||
|
|
||||||
it 'sets the @sender_person object' do
|
it 'sets the @sender_person object' do
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,20 @@ describe Reshare do
|
||||||
it 'forces public' do
|
it 'forces public' do
|
||||||
Factory(:reshare, :public => false).public.should be_true
|
Factory(:reshare, :public => false).public.should be_true
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue