DG RS IZ; added post deletion propagation
This commit is contained in:
parent
de0bff17dd
commit
469599a4a9
7 changed files with 64 additions and 7 deletions
|
|
@ -21,7 +21,9 @@ class Post
|
|||
|
||||
after_save :send_to_view
|
||||
after_save :notify_friends
|
||||
|
||||
|
||||
before_destroy :propagate_delete
|
||||
|
||||
def self.stream
|
||||
Post.sort(:created_at.desc).all
|
||||
end
|
||||
|
|
@ -41,6 +43,9 @@ class Post
|
|||
|
||||
|
||||
protected
|
||||
def propagate_delete
|
||||
Retraction.for(self).notify_friends
|
||||
end
|
||||
|
||||
def send_to_view
|
||||
WebSocket.update_clients(self)
|
||||
|
|
|
|||
18
app/models/retraction.rb
Normal file
18
app/models/retraction.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class Retraction
|
||||
include ROXML
|
||||
include Diaspora::Webhooks
|
||||
|
||||
def self.for(post)
|
||||
result = self.new
|
||||
result.post_id = post.id
|
||||
result.person_id = post.person.id
|
||||
result
|
||||
end
|
||||
|
||||
xml_accessor :post_id
|
||||
xml_accessor :person_id
|
||||
|
||||
attr_accessor :post_id
|
||||
attr_accessor :person_id
|
||||
|
||||
end
|
||||
|
|
@ -18,7 +18,7 @@ module Diaspora
|
|||
body.children.each do |post|
|
||||
begin
|
||||
object = post.name.camelize.constantize.from_xml post.to_s
|
||||
object.person = parse_owner_from_xml post.to_s #if object.is_a? Post
|
||||
object.person = parse_owner_from_xml post.to_s if object.respond_to? :person
|
||||
objects << object
|
||||
rescue
|
||||
puts "Not a real type: #{object.to_s}"
|
||||
|
|
@ -31,8 +31,12 @@ module Diaspora
|
|||
objects = parse_objects_from_xml(xml)
|
||||
|
||||
objects.each do |p|
|
||||
if p.is_a? Retraction
|
||||
Post.delete( p.post_id )
|
||||
#This line checks if the sender was in the database, among other things?
|
||||
p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF
|
||||
elsif p.respond_to?(:person) && !(p.person.nil?) #WTF
|
||||
p.save
|
||||
end
|
||||
#p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@ module SocketRenderer
|
|||
end
|
||||
|
||||
def self.view_for(object)
|
||||
puts object.inspect
|
||||
puts @view.type_partial(object)
|
||||
|
||||
@view.render @view.type_partial(object), :post => object
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ describe Diaspora do
|
|||
end
|
||||
|
||||
it "should send an owners post to their friends" do
|
||||
q = Post.send (:class_variable_get, :@@queue)
|
||||
q = Post.send(:class_variable_get, :@@queue)
|
||||
q.should_receive :process
|
||||
@post.save
|
||||
end
|
||||
|
|
|
|||
|
|
@ -97,7 +97,17 @@ describe "parser in application helper" do
|
|||
comment.person.should == friend
|
||||
comment.post.should == post
|
||||
end
|
||||
|
||||
it 'should marshal retractions' do
|
||||
friend = Factory.create(:friend)
|
||||
message = Factory.create(:status_message, :person => friend)
|
||||
retraction = Retraction.for(message)
|
||||
request = Post.build_xml_for( [retraction] )
|
||||
|
||||
StatusMessage.count.should == 1
|
||||
store_objects_from_xml( request )
|
||||
StatusMessage.count.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
23
spec/models/retraction_spec.rb
Normal file
23
spec/models/retraction_spec.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Retraction do
|
||||
describe "posts" do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@post = Factory.create(:status_message, :person => @user)
|
||||
end
|
||||
|
||||
it 'should have a post id after serialization' do
|
||||
retraction = Retraction.for(@post)
|
||||
xml = retraction.to_xml.to_s
|
||||
xml.include?(@post.id.to_s).should == true
|
||||
end
|
||||
|
||||
it 'should dispatch a message on delete' do
|
||||
Factory.create(:friend)
|
||||
Post.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||
@post.destroy
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue