Fetch linked entities from received entities with text
This commit is contained in:
parent
0b927290e3
commit
add5e16abf
8 changed files with 74 additions and 6 deletions
|
|
@ -24,7 +24,7 @@ module DiasporaFederation
|
|||
# @!attribute [r] description
|
||||
# Description of the event
|
||||
# @return [String] event description
|
||||
property :description, :string, optional: true
|
||||
property :description, :string, alias: :text, optional: true
|
||||
|
||||
# @!attribute [r] start
|
||||
# The start time of the event
|
||||
|
|
|
|||
|
|
@ -43,9 +43,12 @@ module DiasporaFederation
|
|||
# @return [String] url to the small avatar (50x50)
|
||||
property :image_url_small, :string, optional: true
|
||||
|
||||
# @!attribute [r] bio
|
||||
# @return [String] bio of the person
|
||||
property :bio, :string, alias: :text, optional: true
|
||||
|
||||
property :birthday, :string, optional: true
|
||||
property :gender, :string, optional: true
|
||||
property :bio, :string, optional: true
|
||||
property :location, :string, optional: true
|
||||
|
||||
# @!attribute [r] searchable
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ module DiasporaFederation
|
|||
validate
|
||||
DiasporaFederation.callbacks.trigger(:receive_entity, entity, sender, recipient_id)
|
||||
logger.info "successfully received #{entity} from person #{sender}#{" for #{recipient_id}" if recipient_id}"
|
||||
fetch_linked_entities_from_text
|
||||
end
|
||||
|
||||
def validate
|
||||
|
|
@ -43,6 +44,10 @@ module DiasporaFederation
|
|||
sender == entity.author
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_linked_entities_from_text
|
||||
DiasporaUrlParser.fetch_linked_entities(sender, entity.text) if entity.respond_to?(:text) && entity.text
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ module DiasporaFederation
|
|||
<image_url>#{data[:profile].image_url}</image_url>
|
||||
<image_url_medium>#{data[:profile].image_url}</image_url_medium>
|
||||
<image_url_small>#{data[:profile].image_url}</image_url_small>
|
||||
<bio>#{data[:profile].bio}</bio>
|
||||
<birthday>#{data[:profile].birthday}</birthday>
|
||||
<gender>#{data[:profile].gender}</gender>
|
||||
<bio>#{data[:profile].bio}</bio>
|
||||
<location>#{data[:profile].location}</location>
|
||||
<searchable>#{data[:profile].searchable}</searchable>
|
||||
<public>#{data[:profile].public}</public>
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ module DiasporaFederation
|
|||
<image_url>#{data[:profile].image_url}</image_url>
|
||||
<image_url_medium>#{data[:profile].image_url}</image_url_medium>
|
||||
<image_url_small>#{data[:profile].image_url}</image_url_small>
|
||||
<bio>#{data[:profile].bio}</bio>
|
||||
<birthday>#{data[:profile].birthday}</birthday>
|
||||
<gender>#{data[:profile].gender}</gender>
|
||||
<bio>#{data[:profile].bio}</bio>
|
||||
<location>#{data[:profile].location}</location>
|
||||
<searchable>#{data[:profile].searchable}</searchable>
|
||||
<public>#{data[:profile].public}</public>
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ module DiasporaFederation
|
|||
<image_url>#{data[:image_url]}</image_url>
|
||||
<image_url_medium>#{data[:image_url]}</image_url_medium>
|
||||
<image_url_small>#{data[:image_url]}</image_url_small>
|
||||
<bio>#{data[:bio]}</bio>
|
||||
<birthday>#{data[:birthday]}</birthday>
|
||||
<gender>#{data[:gender]}</gender>
|
||||
<bio>#{data[:bio]}</bio>
|
||||
<location>#{data[:location]}</location>
|
||||
<searchable>#{data[:searchable]}</searchable>
|
||||
<public>#{data[:public]}</public>
|
||||
|
|
@ -29,9 +29,9 @@ XML
|
|||
"image_url": "#{data[:image_url]}",
|
||||
"image_url_medium": "#{data[:image_url]}",
|
||||
"image_url_small": "#{data[:image_url]}",
|
||||
"bio": "#{data[:bio]}",
|
||||
"birthday": "#{data[:birthday]}",
|
||||
"gender": "#{data[:gender]}",
|
||||
"bio": "#{data[:bio]}",
|
||||
"location": "#{data[:location]}",
|
||||
"searchable": #{data[:searchable]},
|
||||
"public": #{data[:public]},
|
||||
|
|
|
|||
|
|
@ -112,6 +112,36 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
before do
|
||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
end
|
||||
|
||||
it "fetches linked entities when the received entity has a text property" do
|
||||
expect(Federation::DiasporaUrlParser).to receive(:fetch_linked_entities).with(post.author, post.text)
|
||||
|
||||
described_class.new(magic_env, recipient).receive
|
||||
end
|
||||
|
||||
it "fetches linked entities for the profile bio" do
|
||||
profile = Fabricate(:profile_entity)
|
||||
magic_env = Salmon::MagicEnvelope.new(profile, profile.author)
|
||||
|
||||
expect(Federation::DiasporaUrlParser).to receive(:fetch_linked_entities).with(profile.author, profile.bio)
|
||||
|
||||
described_class.new(magic_env, recipient).receive
|
||||
end
|
||||
|
||||
it "doesn't try to fetch linked entities when the text is nil" do
|
||||
photo = Fabricate(:photo_entity, public: false, text: nil)
|
||||
magic_env = Salmon::MagicEnvelope.new(photo, photo.author)
|
||||
|
||||
expect(Federation::DiasporaUrlParser).not_to receive(:fetch_linked_entities)
|
||||
|
||||
described_class.new(magic_env, recipient).receive
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -134,6 +134,36 @@ module DiasporaFederation
|
|||
described_class.new(magic_env).receive
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
before do
|
||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
end
|
||||
|
||||
it "fetches linked entities when the received entity has a text property" do
|
||||
expect(Federation::DiasporaUrlParser).to receive(:fetch_linked_entities).with(post.author, post.text)
|
||||
|
||||
described_class.new(magic_env).receive
|
||||
end
|
||||
|
||||
it "fetches linked entities for the profile bio" do
|
||||
profile = Fabricate(:profile_entity, public: true)
|
||||
magic_env = Salmon::MagicEnvelope.new(profile, profile.author)
|
||||
|
||||
expect(Federation::DiasporaUrlParser).to receive(:fetch_linked_entities).with(profile.author, profile.bio)
|
||||
|
||||
described_class.new(magic_env).receive
|
||||
end
|
||||
|
||||
it "doesn't try to fetch linked entities when the text is nil" do
|
||||
photo = Fabricate(:photo_entity, text: nil)
|
||||
magic_env = Salmon::MagicEnvelope.new(photo, photo.author)
|
||||
|
||||
expect(Federation::DiasporaUrlParser).not_to receive(:fetch_linked_entities)
|
||||
|
||||
described_class.new(magic_env).receive
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue