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, #missing_props, #optional_props, #property, #resolv_aliases

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:



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

property :author, :string

#created_atTime (readonly)

Post entity creation time

Returns:

  • (Time)

    creation time



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

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:



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

property :guid, :string

#root_authorString (readonly)

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

Returns:

  • (String)

    diaspora* ID

See Also:



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

property :root_author, :string, optional: true

#root_guidString (readonly)

Guid of the original post

Returns:

  • (String)

    root guid

See Also:



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

property :root_guid, :string, optional: true

Class Method Details

.from_hash(hash) ⇒ Entity

Fetch root post after parse

Returns:

See Also:



67
68
69
# File 'lib/diaspora_federation/entities/reshare.rb', line 67

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



39
40
41
# File 'lib/diaspora_federation/entities/reshare.rb', line 39

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.



50
51
52
53
54
55
56
57
58
59
60
61
62
# 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