Commit 602a1dcd authored by Benjamin Neff's avatar Benjamin Neff Committed by Dennis Schubert

Store edited_at for relayables in additional_data

closes #7718
parent 0b4b3515
......@@ -6,6 +6,7 @@
## Bug fixes
* Prevent duplicate mention notifications when the post is received twice [#7721](https://github.com/diaspora/diaspora/pull/7721)
* Fixed a compatiblitiy issue with non-diaspora\* webfingers [#7718](https://github.com/diaspora/diaspora/pull/7718)
## Features
* Add basic html5 audio/video embedding support [#6418](https://github.com/diaspora/diaspora/pull/6418)
......
......@@ -49,6 +49,7 @@ module Diaspora
parent_guid: comment.post.guid,
text: comment.text,
created_at: comment.created_at,
edited_at: comment.signature&.additional_data&.[]("edited_at"),
author_signature: comment.signature.try(:author_signature),
parent: related_entity(comment.post)
},
......
......@@ -272,10 +272,19 @@ module Diaspora
end
end
# This are property names that are known by the +diaspora_federation+ library as properties but not
# specially stored in our database and therefore need to be stored in the +additional_data+ field.
UNKNOWN_PROPERTIES_NAMES = %i[edited_at].freeze
private_constant :UNKNOWN_PROPERTIES_NAMES
private_class_method def self.build_signature(klass, entity)
special_additional_data = UNKNOWN_PROPERTIES_NAMES.map {|name|
[name.to_s, entity.public_send(name)] if entity.respond_to?(name) && entity.signature_order.include?(name)
}.compact.to_h
klass.reflect_on_association(:signature).klass.new(
author_signature: entity.author_signature,
additional_data: entity.additional_data,
additional_data: entity.additional_data.merge(special_additional_data),
signature_order: SignatureOrder.find_or_create_by!(order: entity.signature_order.join(" "))
)
end
......
......@@ -29,6 +29,7 @@ describe Diaspora::Federation::Entities do
expect(federation_entity.guid).to eq(diaspora_entity.guid)
expect(federation_entity.parent_guid).to eq(diaspora_entity.post.guid)
expect(federation_entity.text).to eq(diaspora_entity.text)
expect(federation_entity.created_at).to eq(diaspora_entity.created_at)
expect(federation_entity.author_signature).to be_nil
expect(federation_entity.additional_data).to be_empty
end
......@@ -42,6 +43,27 @@ describe Diaspora::Federation::Entities do
expect(federation_entity.guid).to eq(diaspora_entity.guid)
expect(federation_entity.parent_guid).to eq(diaspora_entity.post.guid)
expect(federation_entity.text).to eq(diaspora_entity.text)
expect(federation_entity.created_at).to eq(diaspora_entity.created_at)
expect(federation_entity.author_signature).to eq(diaspora_entity.signature.author_signature)
expect(federation_entity.signature_order.map(&:to_s)).to eq(diaspora_entity.signature.signature_order.order.split)
expect(federation_entity.additional_data).to eq(diaspora_entity.signature.additional_data)
end
it "builds a comment with edited_at" do
edited_at = Time.now.utc + 3600
diaspora_entity = FactoryGirl.build(
:comment,
signature: FactoryGirl.build(:comment_signature, additional_data: {"edited_at" => edited_at})
)
federation_entity = described_class.build(diaspora_entity)
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Comment)
expect(federation_entity.author).to eq(diaspora_entity.author.diaspora_handle)
expect(federation_entity.guid).to eq(diaspora_entity.guid)
expect(federation_entity.parent_guid).to eq(diaspora_entity.post.guid)
expect(federation_entity.text).to eq(diaspora_entity.text)
expect(federation_entity.created_at).to eq(diaspora_entity.created_at)
expect(federation_entity.edited_at).to eq(edited_at)
expect(federation_entity.author_signature).to eq(diaspora_entity.signature.author_signature)
expect(federation_entity.signature_order.map(&:to_s)).to eq(diaspora_entity.signature.signature_order.order.split)
expect(federation_entity.additional_data).to eq(diaspora_entity.signature.additional_data)
......
......@@ -110,7 +110,7 @@ describe Diaspora::Federation::Receive do
expect(comment.signature).not_to be_nil
expect(comment.signature.author_signature).to eq("aa")
expect(comment.signature.additional_data).to eq("new_property" => "data")
expect(comment.signature.additional_data).to eq("new_property" => "data", "edited_at" => comment_entity.edited_at)
expect(comment.signature.order).to eq(comment_entity.signature_order.map(&:to_s))
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment