From 09d4918e803b26b8b2fda9338ac43487d87c1ed3 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sat, 3 Sep 2011 16:36:15 -0700 Subject: [PATCH] SM MS improve relayable semantics --- lib/diaspora/relayable.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index 09e721d7a..a1f51038e 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -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