logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe
commit: ad5ae3f60e5e0745912bfbc0926f6cf8bc6e9eb4
parent: 2825991e09272d6e7227da9d9b8dc387614a83df
Author: Eugen Rochko <eugen@zeonfederated.com>
Date:   Sun, 28 Feb 2016 14:26:26 +0100

Update profile information and download avatar of remote accounts

Diffstat:

Mapp/helpers/atom_helper.rb22++++++++++++++++------
Mapp/services/follow_remote_account_service.rb15+++++----------
Mapp/services/process_feed_service.rb8++++++++
Mapp/services/process_interaction_service.rb6++++++
Aapp/services/update_remote_profile_service.rb19+++++++++++++++++++
Mapp/views/atom/user_stream.xml.ruby3++-
Mapp/views/profile/_status_footer.html.haml2+-
Mspec/helpers/atom_helper_spec.rb8++++++++
Mspec/helpers/profile_helper_spec.rb22++++++++++++++++++++++
9 files changed, 87 insertions(+), 18 deletions(-)

diff --git a/app/helpers/atom_helper.rb b/app/helpers/atom_helper.rb @@ -100,7 +100,7 @@ module AtomHelper def disambiguate_uri(target) if target.local? if target.object_type == :person - profile_url(name: target.username) + profile_url(target) else unique_tag(target.stream_entry.created_at, target.stream_entry.activity_id, target.stream_entry.activity_type) end @@ -112,9 +112,9 @@ module AtomHelper def disambiguate_url(target) if target.local? if target.object_type == :person - profile_url(name: target.username) + profile_url(target) else - status_url(name: target.stream_entry.account.username, id: target.stream_entry.id) + status_url(target) end else target.url @@ -125,12 +125,21 @@ module AtomHelper xml.link(rel: 'mentioned', href: disambiguate_uri(account)) end + def link_avatar(xml, account) + xml.link(rel: 'avatar', type: account.avatar_content_type, href: asset_url(account.avatar.url(:large))) + end + + def logo(xml, url) + xml.logo url + end + def include_author(xml, account) object_type xml, :person - uri xml, profile_url(name: account.username) + uri xml, profile_url(account) name xml, account.username summary xml, account.note - link_alternate xml, profile_url(name: account.username) + link_alternate xml, profile_url(account) + link_avatar xml, account portable_contact xml, account end @@ -160,6 +169,7 @@ module AtomHelper if stream_entry.target.object_type == :person summary xml, stream_entry.target.content portable_contact xml, stream_entry.target + link_avatar xml, stream_entry.target end # Statuses have content @@ -177,6 +187,6 @@ module AtomHelper private def root_tag(xml, tag, &block) - xml.send(tag, { :xmlns => 'http://www.w3.org/2005/Atom', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0', 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/', 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0' }, &block) + xml.send(tag, { :xmlns => 'http://www.w3.org/2005/Atom', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0', 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/', 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0', 'xmlns:media' => 'http://purl.org/syndication/atommedia' }, &block) end end diff --git a/app/services/follow_remote_account_service.rb b/app/services/follow_remote_account_service.rb @@ -58,16 +58,7 @@ class FollowRemoteAccountService < BaseService def get_profile(xml, account) author = xml.at_xpath('/xmlns:feed/xmlns:author') - - if author.at_xpath('./poco:displayName').nil? - account.display_name = account.username - else - account.display_name = author.at_xpath('./poco:displayName').content - end - - unless author.at_xpath('./poco:note').nil? - account.note = author.at_xpath('./poco:note').content - end + update_remote_profile_service.(author, account) end def magic_key_to_pem(magic_key) @@ -81,6 +72,10 @@ class FollowRemoteAccountService < BaseService key.to_pem end + def update_remote_profile_service + @update_remote_profile_service ||= UpdateRemoteProfileService.new + end + def http_client HTTP end diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb @@ -5,6 +5,10 @@ class ProcessFeedService < BaseService def call(body, account) xml = Nokogiri::XML(body) + unless xml.at_xpath('/xmlns:feed').nil? + update_remote_profile_service.(xml.at_xpath('/xmlns:feed/xmlns:author'), account) + end + xml.xpath('//xmlns:entry').each do |entry| next unless [:note, :comment, :activity].includes? object_type(entry) @@ -126,4 +130,8 @@ class ProcessFeedService < BaseService def process_mentions_service @process_mentions_service ||= ProcessMentionsService.new end + + def update_remote_profile_service + @update_remote_profile_service ||= UpdateRemoteProfileService.new + end end diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb @@ -19,6 +19,8 @@ class ProcessInteractionService < BaseService end if salmon.verify(envelope, account.keypair) + update_remote_profile_service.(xml.at_xpath('/xmlns:entry/xmlns:author'), account) + case verb(xml) when :follow follow!(account, target_account) @@ -86,4 +88,8 @@ class ProcessInteractionService < BaseService def process_feed_service @process_feed_service ||= ProcessFeedService.new end + + def update_remote_profile_service + @update_remote_profile_service ||= UpdateRemoteProfileService.new + end end diff --git a/app/services/update_remote_profile_service.rb b/app/services/update_remote_profile_service.rb @@ -0,0 +1,19 @@ +class UpdateRemoteProfileService < BaseService + def call(author_xml, account) + if author_xml.at_xpath('./poco:displayName').nil? + account.display_name = account.username + else + account.display_name = author_xml.at_xpath('./poco:displayName').content + end + + unless author_xml.at_xpath('./poco:note').nil? + account.note = author_xml.at_xpath('./poco:note').content + end + + unless author_xml.at_xpath('./xmlns:link[@rel="avatar"]').nil? + account.avatar_remote_url = author_xml.at_xpath('./xmlns:link[@rel="avatar"]').attribute('href').value + end + + account.save! + end +end diff --git a/app/views/atom/user_stream.xml.ruby b/app/views/atom/user_stream.xml.ruby @@ -4,12 +4,13 @@ Nokogiri::XML::Builder.new do |xml| title xml, @account.display_name subtitle xml, @account.note updated_at xml, stream_updated_at + logo xml, asset_url(@account.avatar.url(:medium)) author(xml) do include_author xml, @account end - link_alternate xml, profile_url(name: @account.username) + link_alternate xml, profile_url(@account) link_self xml, atom_user_stream_url(id: @account.id) link_hub xml, HUB_URL link_salmon xml, salmon_url(@account) diff --git a/app/views/profile/_status_footer.html.haml b/app/views/profile/_status_footer.html.haml @@ -7,4 +7,4 @@ %span.num= status.favourites.count - if status.reply? - = link_to 'View conversation', status_url(status.thread), class: 'conversation-link' + = link_to "In response to #{status.thread.account.acct}", status_url(status.thread), class: 'conversation-link' diff --git a/spec/helpers/atom_helper_spec.rb b/spec/helpers/atom_helper_spec.rb @@ -112,4 +112,12 @@ RSpec.describe AtomHelper, type: :helper do describe '#include_entry' do pending end + + describe '#link_avatar' do + pending + end + + describe '#logo' do + pending + end end diff --git a/spec/helpers/profile_helper_spec.rb b/spec/helpers/profile_helper_spec.rb @@ -1,5 +1,27 @@ require 'rails_helper' RSpec.describe ProfileHelper, type: :helper do + describe '#display_name' do + pending + end + describe '#profile_url' do + pending + end + + describe '#status_url' do + pending + end + + describe '#avatar_for_status_url' do + pending + end + + describe '#entry_classes' do + pending + end + + describe '#relative_time' do + pending + end end