SM MS improve relayable semantics

This commit is contained in:
Maxwell Salzberg 2011-09-03 16:36:15 -07:00
parent 0780491d4f
commit 09d4918e80

View file

@ -37,28 +37,30 @@ module Diaspora
def receive(user, person)
self.class.transaction do
object = self.class.where(:guid => self.guid).first || self
comment_or_like = self.class.where(:guid => self.guid).first || self
unless object.parent.author == user.person || object.verify_parent_author_signature
#check to make sure the signature of the comment or like comes from the person claiming to authoring said comment or like
unless comment_or_like.parent.author == user.person || comment_or_like.verify_parent_author_signature
Rails.logger.info("event=receive status=abort reason='object signature not valid' recipient=#{user.diaspora_handle} sender=#{self.parent.author.diaspora_handle} payload_type=#{self.class} parent_id=#{self.parent.id}")
return
end
#sign object as the parent creator if you've been hit UPSTREAM
if user.owns? object.parent
object.parent_author_signature = object.sign_with_key(user.encryption_key)
object.save!
#as the owner of the post being liked or commented on, you need to add your own signature in order to pass it to the people who received your original post
if user.owns? comment_or_like.parent
comment_or_like.parent_author_signature = comment_or_like.sign_with_key(user.encryption_key)
comment_or_like.save!
end
#dispatch object DOWNSTREAM, received it via UPSTREAM
unless user.owns?(object)
object.save
Postzord::Dispatch.new(user, object).post
unless user.owns?(comment_or_like)
comment_or_like.save
Postzord::Dispatch.new(user, comment_or_like).post
end
object.socket_to_user(user) if object.respond_to? :socket_to_user
if object.after_receive(user, person)
object
comment_or_like.socket_to_user(user) if comment_or_like.respond_to? :socket_to_user
if comment_or_like.after_receive(user, person)
comment_or_like
end
end
end