checking for relayable in the dispatcher and the receiver

This commit is contained in:
zhitomirskiyi 2011-03-08 11:55:17 -08:00
parent 8bcf1b49c7
commit 9490538e44
3 changed files with 8 additions and 4 deletions

View file

@ -13,6 +13,10 @@ module Diaspora
xml_attr :author_signature
end
end
def relayable
true
end
def parent_guid
self.parent.guid

View file

@ -22,7 +22,7 @@ class Postzord::Dispatch
unless @subscribers == nil
remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? }
if @object.is_a?(Comment) && @sender.owns?(@object.post)
if @object.respond_to?(:relayable) && @sender.owns?(@object.parent)
user_ids = [*local_people].map{|x| x.owner_id }
local_users = User.where(:id => user_ids)
self.notify_users(local_users)

View file

@ -49,9 +49,9 @@ module Postzord
end
def xml_author
if @object.is_a?(Comment)
if @object.respond_to?(:relayable)
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
xml_author = @user.owns?(@object.post) ? @object.diaspora_handle : @object.post.author.diaspora_handle
xml_author = @user.owns?(@object.parent) ? @object.diaspora_handle : @object.parent.author.diaspora_handle
@author = Webfinger.new(@object.diaspora_handle).fetch
else
xml_author = @object.diaspora_handle
@ -71,7 +71,7 @@ module Postzord
end
# abort if we haven't received the post to a comment
if @object.is_a?(Comment) && @object.post.nil?
if @object.respond_to?(:relayable) && @object.parent.nil?
Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})")
return false
end