Class: DiasporaFederation::Entities::Reshare
- Inherits:
-
DiasporaFederation::Entity
- Object
- DiasporaFederation::Entity
- DiasporaFederation::Entities::Reshare
- 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
-
#author ⇒ String
readonly
The diaspora* ID of the person who reshares the post.
-
#created_at ⇒ Time
readonly
Post entity creation time.
-
#guid ⇒ String
readonly
A random string of at least 16 chars.
-
#root_author ⇒ String
readonly
The diaspora* ID of the person who posted the original post.
-
#root_guid ⇒ String
readonly
Guid of the original post.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Entity
Fetch root post after parse.
Instance Method Summary collapse
-
#to_s ⇒ String
String representation of this object.
-
#validate_root ⇒ Object
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.
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
Constructor Details
This class inherits a constructor from DiasporaFederation::Entity
Instance Attribute Details
#author ⇒ String (readonly)
The diaspora* ID of the person who reshares the post
13 |
# File 'lib/diaspora_federation/entities/reshare.rb', line 13 property :author, :string |
#created_at ⇒ Time (readonly)
Post entity creation time
24 |
# File 'lib/diaspora_federation/entities/reshare.rb', line 24 property :created_at, :timestamp, default: -> { Time.now.utc } |
#guid ⇒ String (readonly)
A random string of at least 16 chars
19 |
# File 'lib/diaspora_federation/entities/reshare.rb', line 19 property :guid, :string |
#root_author ⇒ String (readonly)
The diaspora* ID of the person who posted the original post
30 |
# File 'lib/diaspora_federation/entities/reshare.rb', line 30 property :root_author, :string, optional: true |
#root_guid ⇒ String (readonly)
Guid of the original post
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
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_s ⇒ String
Returns 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_root ⇒ Object
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 .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 .nil? root = RelatedEntity.fetch(, "Post", root_guid) return if == root. raise Entity::ValidationError, "root_author mismatch: obj=#{self} root_author=#{} known_root_author=#{root.}" end |