class DiasporaFederation::Entities::Reshare

This entity represents the fact that a user reshared another user’s post.

@see Validators::ReshareValidator

Public Class Methods

from_hash(hash) click to toggle source

Fetch root post after parse @see Entity.from_hash @return [Entity] instance

Calls superclass method
# File lib/diaspora_federation/entities/reshare.rb, line 67
def self.from_hash(hash)
  super.tap(&:validate_root)
end

Public Instance Methods

to_s() click to toggle source

@return [String] string representation of this object

# File lib/diaspora_federation/entities/reshare.rb, line 39
def to_s
  "#{super}:#{root_guid}"
end
validate_root() click to toggle source

Fetch and receive root post from remote, if not available locally and validates if it’s from the correct author TODO: after reshares are only used to increase the reach of a post (and legacy reshares with own interactions are migrated to the new form), root_author and root_guid aren’t allowed to be empty anymore, so a not_nil check should be added to the validator and the first few lines here can be removed.

# File lib/diaspora_federation/entities/reshare.rb, line 50
def validate_root
  return if root_author.nil? && root_guid.nil?

  raise Entity::ValidationError, "#{self}: root_guid can't be nil if root_author is present" if root_guid.nil?
  raise Entity::ValidationError, "#{self}: root_author can't be nil if root_guid is present" if root_author.nil?

  root = RelatedEntity.fetch(root_author, "Post", root_guid)

  return if root_author == root.author

  raise Entity::ValidationError,
        "root_author mismatch: obj=#{self} root_author=#{root_author} known_root_author=#{root.author}"
end