From 23d3d9dc3f4aaa1e8838cbd0f81bbb1384f35188 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Tue, 11 Apr 2017 11:33:43 +0200 Subject: [PATCH] Use post page title for atom feeds and add entry author Fixes #7249 closes #7420 --- Changelog.md | 1 + app/helpers/activity_streams_helper.rb | 12 ++++++ app/views/users/public.atom.builder | 13 ++----- spec/controllers/users_controller_spec.rb | 47 ++++++++++++++++------- 4 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 app/helpers/activity_streams_helper.rb diff --git a/Changelog.md b/Changelog.md index 7dfc5dbb5..7b34eba4e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ ## Bug fixes * Make photo upload button hover text translatable [#7429](https://github.com/diaspora/diaspora/pull/7429) * Fix first comment in mobile view with french locale [#7441](https://github.com/diaspora/diaspora/pull/7441) +* Use post page title and post author in atom feed [#7420](https://github.com/diaspora/diaspora/pull/7420) ## Features diff --git a/app/helpers/activity_streams_helper.rb b/app/helpers/activity_streams_helper.rb new file mode 100644 index 000000000..b08514404 --- /dev/null +++ b/app/helpers/activity_streams_helper.rb @@ -0,0 +1,12 @@ +module ActivityStreamsHelper + def add_activitystreams_author(target, person) + target.author do |author| + author.name person.name + author.uri local_or_remote_person_path(person, absolute: true) + + author.tag! "activity:object-type", "http://activitystrea.ms/schema/1.0/person" + author.tag! "poco:preferredUsername", person.username + author.tag! "poco:displayName", person.name + end + end +end diff --git a/app/views/users/public.atom.builder b/app/views/users/public.atom.builder index e5bfb6da8..790f6f21a 100644 --- a/app/views/users/public.atom.builder +++ b/app/views/users/public.atom.builder @@ -17,21 +17,16 @@ atom_feed("xmlns:thr" => "http://purl.org/syndication/thread/1.0", 'media:height' => '100', :href => "#{@user.image_url}" feed.tag! :link, :href => "#{AppConfig.environment.pubsub_server}", :rel => 'hub' - feed.author do |author| - author.name @user.name - author.uri local_or_remote_person_path(@user.person, :absolute => true) - - author.tag! 'activity:object-type', 'http://activitystrea.ms/schema/1.0/person' - author.tag! 'poco:preferredUsername', @user.username - author.tag! 'poco:displayName', @user.name - end + add_activitystreams_author(feed, @user.person) @posts.each do |post| feed.entry post, :url => "#{@user.url}p/#{post.id}", :id => "#{@user.url}p/#{post.id}" do |entry| - entry.title post.message.title + entry.title post_page_title(post) entry.content post.message.markdownified(disable_hovercards: true), :type => 'html' + add_activitystreams_author(entry, post.author) + entry.tag! 'activity:verb', 'http://activitystrea.ms/schema/1.0/post' entry.tag! 'activity:object-type', 'http://activitystrea.ms/schema/1.0/note' end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index a80f9f37e..327780607 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -4,6 +4,7 @@ describe UsersController, :type => :controller do include_context :gon + include PostsHelper before do @user = alice @@ -46,20 +47,40 @@ describe UsersController, :type => :controller do end describe '#public' do - it 'renders xml if atom is requested' do - sm = FactoryGirl.create(:status_message, :public => true, :author => @user.person) - get :public, :username => @user.username, :format => :atom - expect(response.body).to include(sm.text) - end - - it 'renders xml if atom is requested with clickalbe urls' do - sm = FactoryGirl.create(:status_message, :public => true, :author => @user.person) - @user.person.posts.each do |p| - p.text = "Goto http://diasporaproject.org/ now!" - p.save + context "entry xml contents" do + before do + @sm = FactoryGirl.create( + :status_message, + public: true, + author: @user.person, + text: "Go to http://diasporafoundation.org/ now!" + ) + end + + it "contains the text" do + get :public, username: @user.username, format: :atom + doc = Nokogiri::XML(response.body) + expect(doc.css("entry content")[0].content).to eq(@sm.message.markdownified(disable_hovercards: true)) + end + + it "contains the title" do + get :public, username: @user.username, format: :atom + doc = Nokogiri::XML(response.body) + expect(doc.css("entry title")[0].content).to eq(post_page_title(@sm)) + end + + it "contains the author" do + get :public, username: @user.username, format: :atom + doc = Nokogiri::XML(response.body) + expect(doc.css("entry author name")[0].content).to eq(@sm.author_name) + end + + it "contains the original author for reshares" do + FactoryGirl.create(:reshare, root: @sm, author: bob.person) + get :public, username: bob.username, format: :atom + doc = Nokogiri::XML(response.body) + expect(doc.css("entry author name")[0].content).to eq(@sm.author_name) end - get :public, :username => @user.username, :format => :atom - expect(response.body).to include('a href') end it 'includes reshares in the atom feed' do