move guid and diaspora_id to Relayable
This commit is contained in:
parent
eb486b2a18
commit
cf5da6e1ab
13 changed files with 41 additions and 89 deletions
|
|
@ -8,24 +8,12 @@ module DiasporaFederation
|
||||||
# @deprecated
|
# @deprecated
|
||||||
LEGACY_SIGNATURE_ORDER = %i(guid parent_guid text diaspora_id).freeze
|
LEGACY_SIGNATURE_ORDER = %i(guid parent_guid text diaspora_id).freeze
|
||||||
|
|
||||||
# @!attribute [r] guid
|
|
||||||
# a random string of at least 16 chars.
|
|
||||||
# @see Validation::Rule::Guid
|
|
||||||
# @return [String] comment guid
|
|
||||||
property :guid
|
|
||||||
|
|
||||||
include Relayable
|
include Relayable
|
||||||
|
|
||||||
# @!attribute [r] text
|
# @!attribute [r] text
|
||||||
# @return [String] the comment text
|
# @return [String] the comment text
|
||||||
property :text
|
property :text
|
||||||
|
|
||||||
# @!attribute [r] diaspora_id
|
|
||||||
# The diaspora ID of the author.
|
|
||||||
# @see Person#diaspora_id
|
|
||||||
# @return [String] diaspora ID
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
|
||||||
|
|
||||||
# The {Comment} parent is a Post
|
# The {Comment} parent is a Post
|
||||||
# @return [String] parent type
|
# @return [String] parent type
|
||||||
def parent_type
|
def parent_type
|
||||||
|
|
|
||||||
|
|
@ -8,32 +8,20 @@ module DiasporaFederation
|
||||||
# @deprecated
|
# @deprecated
|
||||||
LEGACY_SIGNATURE_ORDER = %i(positive guid parent_type parent_guid diaspora_id).freeze
|
LEGACY_SIGNATURE_ORDER = %i(positive guid parent_type parent_guid diaspora_id).freeze
|
||||||
|
|
||||||
|
include Relayable
|
||||||
|
|
||||||
# @!attribute [r] positive
|
# @!attribute [r] positive
|
||||||
# If +true+ set a like, if +false+, set a dislike (dislikes are currently not
|
# If +true+ set a like, if +false+, set a dislike (dislikes are currently not
|
||||||
# implemented in the Diaspora frontend).
|
# implemented in the Diaspora frontend).
|
||||||
# @return [Boolean] is it a like or a dislike
|
# @return [Boolean] is it a like or a dislike
|
||||||
property :positive
|
property :positive
|
||||||
|
|
||||||
# @!attribute [r] guid
|
|
||||||
# a random string of at least 16 chars.
|
|
||||||
# @see Validation::Rule::Guid
|
|
||||||
# @return [String] like guid
|
|
||||||
property :guid
|
|
||||||
|
|
||||||
# @!attribute [r] parent_type
|
# @!attribute [r] parent_type
|
||||||
# A string describing the type of the parent.
|
# A string describing the type of the parent.
|
||||||
# Can be "Post" or "Comment" (Comments are currently not implemented in the
|
# Can be "Post" or "Comment" (Comments are currently not implemented in the
|
||||||
# Diaspora Frontend).
|
# Diaspora Frontend).
|
||||||
# @return [String] parent type
|
# @return [String] parent type
|
||||||
property :parent_type, xml_name: :target_type
|
property :parent_type, xml_name: :target_type
|
||||||
|
|
||||||
include Relayable
|
|
||||||
|
|
||||||
# @!attribute [r] diaspora_id
|
|
||||||
# The diaspora ID of the person who posts a like
|
|
||||||
# @see Person#diaspora_id
|
|
||||||
# @return [String] diaspora ID
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,6 @@ module DiasporaFederation
|
||||||
# @deprecated
|
# @deprecated
|
||||||
LEGACY_SIGNATURE_ORDER = %i(guid parent_guid text created_at diaspora_id conversation_guid).freeze
|
LEGACY_SIGNATURE_ORDER = %i(guid parent_guid text created_at diaspora_id conversation_guid).freeze
|
||||||
|
|
||||||
# @!attribute [r] guid
|
|
||||||
# a random string of at least 16 chars.
|
|
||||||
# @see Validation::Rule::Guid
|
|
||||||
# @return [String] message guid
|
|
||||||
property :guid
|
|
||||||
|
|
||||||
include Relayable
|
include Relayable
|
||||||
|
|
||||||
# @!attribute [r] text
|
# @!attribute [r] text
|
||||||
|
|
@ -26,12 +20,6 @@ module DiasporaFederation
|
||||||
# @return [Time] creation time
|
# @return [Time] creation time
|
||||||
property :created_at, default: -> { Time.now.utc }
|
property :created_at, default: -> { Time.now.utc }
|
||||||
|
|
||||||
# @!attribute [r] diaspora_id
|
|
||||||
# The diaspora ID of the message author.
|
|
||||||
# @see Person#diaspora_id
|
|
||||||
# @return [String] diaspora ID
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
|
||||||
|
|
||||||
# @!attribute [r] conversation_guid
|
# @!attribute [r] conversation_guid
|
||||||
# guid of a conversation this message belongs to
|
# guid of a conversation this message belongs to
|
||||||
# @see Conversation#guid
|
# @see Conversation#guid
|
||||||
|
|
|
||||||
|
|
@ -8,25 +8,13 @@ module DiasporaFederation
|
||||||
# @deprecated
|
# @deprecated
|
||||||
LEGACY_SIGNATURE_ORDER = %i(guid parent_type parent_guid diaspora_id).freeze
|
LEGACY_SIGNATURE_ORDER = %i(guid parent_type parent_guid diaspora_id).freeze
|
||||||
|
|
||||||
# @!attribute [r] guid
|
include Relayable
|
||||||
# a random string of at least 16 chars.
|
|
||||||
# @see Validation::Rule::Guid
|
|
||||||
# @return [String] participation guid
|
|
||||||
property :guid
|
|
||||||
|
|
||||||
# @!attribute [r] parent_type
|
# @!attribute [r] parent_type
|
||||||
# a string describing a type of the target to subscribe on.
|
# a string describing a type of the target to subscribe on.
|
||||||
# currently only "Post" is supported.
|
# currently only "Post" is supported.
|
||||||
# @return [String] parent type
|
# @return [String] parent type
|
||||||
property :parent_type, xml_name: :target_type
|
property :parent_type, xml_name: :target_type
|
||||||
|
|
||||||
include Relayable
|
|
||||||
|
|
||||||
# @!attribute [r] diaspora_id
|
|
||||||
# The diaspora ID of the person who subscribes on a post
|
|
||||||
# @see Person#diaspora_id
|
|
||||||
# @return [String] diaspora ID
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,8 @@ module DiasporaFederation
|
||||||
# @deprecated
|
# @deprecated
|
||||||
LEGACY_SIGNATURE_ORDER = %i(guid parent_guid diaspora_id poll_answer_guid).freeze
|
LEGACY_SIGNATURE_ORDER = %i(guid parent_guid diaspora_id poll_answer_guid).freeze
|
||||||
|
|
||||||
# @!attribute [r] guid
|
|
||||||
# a random string of at least 16 chars.
|
|
||||||
# @see Validation::Rule::Guid
|
|
||||||
# @return [String] guid
|
|
||||||
property :guid
|
|
||||||
|
|
||||||
include Relayable
|
include Relayable
|
||||||
|
|
||||||
# @!attribute [r] diaspora_id
|
|
||||||
# The diaspora ID of the person who voted in the poll
|
|
||||||
# @see Person#diaspora_id
|
|
||||||
# @return [String] diaspora ID
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
|
||||||
|
|
||||||
# @!attribute [r] poll_answer_guid
|
# @!attribute [r] poll_answer_guid
|
||||||
# guid of the answer selected by the user.
|
# guid of the answer selected by the user.
|
||||||
# @see PollAnswer#guid
|
# @see PollAnswer#guid
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,26 @@ module DiasporaFederation
|
||||||
|
|
||||||
# on inclusion of this module the required properties for a relayable are added to the object that includes it
|
# on inclusion of this module the required properties for a relayable are added to the object that includes it
|
||||||
#
|
#
|
||||||
|
# @!attribute [r] diaspora_id
|
||||||
|
# The diaspora ID of the author.
|
||||||
|
# @see Person#diaspora_id
|
||||||
|
# @return [String] diaspora ID
|
||||||
|
#
|
||||||
|
# @!attribute [r] guid
|
||||||
|
# a random string of at least 16 chars.
|
||||||
|
# @see Validation::Rule::Guid
|
||||||
|
# @return [String] comment guid
|
||||||
|
#
|
||||||
# @!attribute [r] parent_guid
|
# @!attribute [r] parent_guid
|
||||||
# @see StatusMessage#guid
|
# @see StatusMessage#guid
|
||||||
# @return [String] parent guid
|
# @return [String] parent guid
|
||||||
#
|
#
|
||||||
|
# @!attribute [r] author_signature
|
||||||
|
# Contains a signature of the entity using the private key of the author of a post itself.
|
||||||
|
# The presence of this signature is mandatory. Without it the entity won't be accepted by
|
||||||
|
# a target pod.
|
||||||
|
# @return [String] author signature
|
||||||
|
#
|
||||||
# @!attribute [r] parent_author_signature
|
# @!attribute [r] parent_author_signature
|
||||||
# Contains a signature of the entity using the private key of the author of a parent post
|
# Contains a signature of the entity using the private key of the author of a parent post
|
||||||
# This signature is required only when federation from upstream (parent) post author to
|
# This signature is required only when federation from upstream (parent) post author to
|
||||||
|
|
@ -24,18 +40,14 @@ module DiasporaFederation
|
||||||
#
|
#
|
||||||
# @return [String] parent author signature
|
# @return [String] parent author signature
|
||||||
#
|
#
|
||||||
# @!attribute [r] author_signature
|
|
||||||
# Contains a signature of the entity using the private key of the author of a post itself.
|
|
||||||
# The presence of this signature is mandatory. Without it the entity won't be accepted by
|
|
||||||
# a target pod.
|
|
||||||
# @return [String] author signature
|
|
||||||
#
|
|
||||||
# @param [Entity] entity the entity in which it is included
|
# @param [Entity] entity the entity in which it is included
|
||||||
def self.included(entity)
|
def self.included(entity)
|
||||||
entity.class_eval do
|
entity.class_eval do
|
||||||
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
property :guid
|
||||||
property :parent_guid
|
property :parent_guid
|
||||||
property :parent_author_signature, default: nil
|
|
||||||
property :author_signature, default: nil
|
property :author_signature, default: nil
|
||||||
|
property :parent_author_signature, default: nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ module DiasporaFederation
|
||||||
# recipient_pubkey = however_you_retrieve_the_recipients_public_key()
|
# recipient_pubkey = however_you_retrieve_the_recipients_public_key()
|
||||||
# entity = YourEntity.new(attr: "val")
|
# entity = YourEntity.new(attr: "val")
|
||||||
#
|
#
|
||||||
# slap_xml = EncryptedSlap.generate_xml(author_id, author_privkey, entity, recipient_pubkey)
|
# slap_xml = EncryptedSlap.prepare(author_id, author_privkey, entity).generate_xml(recipient_pubkey)
|
||||||
#
|
#
|
||||||
# @example Parsing a Salmon Slap
|
# @example Parsing a Salmon Slap
|
||||||
# recipient_privkey = however_you_retrieve_the_recipients_private_key()
|
# recipient_privkey = however_you_retrieve_the_recipients_private_key()
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ module DiasporaFederation
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
<<-XML
|
<<-XML
|
||||||
<comment>
|
<comment>
|
||||||
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<parent_guid>#{parent.guid}</parent_guid>
|
<parent_guid>#{parent.guid}</parent_guid>
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
|
||||||
<author_signature>#{data[:author_signature]}</author_signature>
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
<text>#{data[:text]}</text>
|
<text>#{data[:text]}</text>
|
||||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
|
||||||
</comment>
|
</comment>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ module DiasporaFederation
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
<<-XML
|
<<-XML
|
||||||
<like>
|
<like>
|
||||||
<positive>#{data[:positive]}</positive>
|
|
||||||
<guid>#{data[:guid]}</guid>
|
|
||||||
<target_type>#{parent.entity_type}</target_type>
|
|
||||||
<parent_guid>#{parent.guid}</parent_guid>
|
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
|
||||||
<author_signature>#{data[:author_signature]}</author_signature>
|
|
||||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<parent_guid>#{parent.guid}</parent_guid>
|
||||||
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
|
<positive>#{data[:positive]}</positive>
|
||||||
|
<target_type>#{parent.entity_type}</target_type>
|
||||||
</like>
|
</like>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ module DiasporaFederation
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
<<-XML
|
<<-XML
|
||||||
<message>
|
<message>
|
||||||
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<parent_guid>#{parent.guid}</parent_guid>
|
<parent_guid>#{parent.guid}</parent_guid>
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
|
||||||
<author_signature>#{data[:author_signature]}</author_signature>
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
<text>#{data[:text]}</text>
|
<text>#{data[:text]}</text>
|
||||||
<created_at>#{data[:created_at]}</created_at>
|
<created_at>#{data[:created_at]}</created_at>
|
||||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
|
||||||
<conversation_guid>#{data[:conversation_guid]}</conversation_guid>
|
<conversation_guid>#{data[:conversation_guid]}</conversation_guid>
|
||||||
</message>
|
</message>
|
||||||
XML
|
XML
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ module DiasporaFederation
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
<<-XML
|
<<-XML
|
||||||
<participation>
|
<participation>
|
||||||
<guid>#{data[:guid]}</guid>
|
|
||||||
<target_type>#{parent.entity_type}</target_type>
|
|
||||||
<parent_guid>#{parent.guid}</parent_guid>
|
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
|
||||||
<author_signature>#{data[:author_signature]}</author_signature>
|
|
||||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<parent_guid>#{parent.guid}</parent_guid>
|
||||||
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
|
<target_type>#{parent.entity_type}</target_type>
|
||||||
</participation>
|
</participation>
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ module DiasporaFederation
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
<<-XML
|
<<-XML
|
||||||
<poll_participation>
|
<poll_participation>
|
||||||
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<parent_guid>#{parent.guid}</parent_guid>
|
<parent_guid>#{parent.guid}</parent_guid>
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
|
||||||
<author_signature>#{data[:author_signature]}</author_signature>
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
<poll_answer_guid>#{data[:poll_answer_guid]}</poll_answer_guid>
|
<poll_answer_guid>#{data[:poll_answer_guid]}</poll_answer_guid>
|
||||||
</poll_participation>
|
</poll_participation>
|
||||||
XML
|
XML
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ shared_examples "a relayable Entity" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "computes correct signatures for the entity" do
|
it "computes correct signatures for the entity" do
|
||||||
signed_string = instance.to_h.map {|name, value| value.to_s unless name =~ /signature/ }.compact.join(";")
|
signed_string = described_class::LEGACY_SIGNATURE_ORDER.map {|name| data[name] }.join(";")
|
||||||
|
|
||||||
xml = DiasporaFederation::Salmon::XmlPayload.pack(instance)
|
xml = DiasporaFederation::Salmon::XmlPayload.pack(instance)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue