Skip to content
Extraits de code Groupes Projets
Valider 469599a4 rédigé par danielvincent's avatar danielvincent
Parcourir les fichiers

DG RS IZ; added post deletion propagation

parent de0bff17
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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)
......
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
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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter