Class: DiasporaFederation::Entities::Reshare

Inherits:
DiasporaFederation::Entity show all
Defined in:
lib/diaspora_federation/entities/reshare.rb

Overview

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

Constant Summary

Constants inherited from DiasporaFederation::Entity

DiasporaFederation::Entity::ENTITY_NAME_REGEX, DiasporaFederation::Entity::INVALID_XML_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DiasporaFederation::Entity

class_name, entity_class, entity_name, from_json, from_xml, #initialize, #to_h, #to_json, #to_xml

Methods included from PropertiesDSL

#class_props, #default_values, #entity, #find_property_for_xml_name, #missing_props, #optional_props, #property, #resolv_aliases, #xml_names

Methods included from Logging

included

Constructor Details

This class inherits a constructor from DiasporaFederation::Entity

Instance Attribute Details

#authorString (readonly)

The diaspora* ID of the person who reshares the post

Returns:

  • (String)

    diaspora* ID

See Also:



11
# File 'lib/diaspora_federation/entities/reshare.rb', line 11

property :author, :string, xml_name: :diaspora_handle

#created_atTime (readonly)

Post entity creation time

Returns:

  • (Time)

    creation time



22
# File 'lib/diaspora_federation/entities/reshare.rb', line 22

property :created_at, :timestamp, default: -> { Time.now.utc }

#guidString (readonly)

A random string of at least 16 chars

Returns:

  • (String)

    status message guid

See Also:



17
# File 'lib/diaspora_federation/entities/reshare.rb', line 17

property :guid, :string

#root_authorString (readonly)

The diaspora* ID of the person who posted the original post

Returns:

  • (String)

    diaspora* ID

See Also:



28
# File 'lib/diaspora_federation/entities/reshare.rb', line 28

property :root_author, :string, optional: true, xml_name: :root_diaspora_id

#root_guidString (readonly)

Guid of the original post

Returns:

  • (String)

    root guid

See Also:



34
# File 'lib/diaspora_federation/entities/reshare.rb', line 34

property :root_guid, :string, optional: true

Class Method Details

.from_hash(hash) ⇒ Entity

Fetch root post after parse

Returns:

See Also:



65
66
67
# File 'lib/diaspora_federation/entities/reshare.rb', line 65

def self.from_hash(hash)
  super.tap(&:validate_root)
end

Instance Method Details

#to_sString

Returns string representation of this object

Returns:

  • (String)

    string representation of this object



37
38
39
# File 'lib/diaspora_federation/entities/reshare.rb', line 37

def to_s
  "#{super}:#{root_guid}"
end

#validate_rootObject

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.



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/diaspora_federation/entities/reshare.rb', line 48

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