mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-16 11:53:13 +00:00
Update profile information and download avatar of remote accounts
This commit is contained in:
parent
2825991e09
commit
ad5ae3f60e
|
@ -100,7 +100,7 @@ module AtomHelper
|
||||||
def disambiguate_uri(target)
|
def disambiguate_uri(target)
|
||||||
if target.local?
|
if target.local?
|
||||||
if target.object_type == :person
|
if target.object_type == :person
|
||||||
profile_url(name: target.username)
|
profile_url(target)
|
||||||
else
|
else
|
||||||
unique_tag(target.stream_entry.created_at, target.stream_entry.activity_id, target.stream_entry.activity_type)
|
unique_tag(target.stream_entry.created_at, target.stream_entry.activity_id, target.stream_entry.activity_type)
|
||||||
end
|
end
|
||||||
|
@ -112,9 +112,9 @@ module AtomHelper
|
||||||
def disambiguate_url(target)
|
def disambiguate_url(target)
|
||||||
if target.local?
|
if target.local?
|
||||||
if target.object_type == :person
|
if target.object_type == :person
|
||||||
profile_url(name: target.username)
|
profile_url(target)
|
||||||
else
|
else
|
||||||
status_url(name: target.stream_entry.account.username, id: target.stream_entry.id)
|
status_url(target)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
target.url
|
target.url
|
||||||
|
@ -125,12 +125,21 @@ module AtomHelper
|
||||||
xml.link(rel: 'mentioned', href: disambiguate_uri(account))
|
xml.link(rel: 'mentioned', href: disambiguate_uri(account))
|
||||||
end
|
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)
|
def include_author(xml, account)
|
||||||
object_type xml, :person
|
object_type xml, :person
|
||||||
uri xml, profile_url(name: account.username)
|
uri xml, profile_url(account)
|
||||||
name xml, account.username
|
name xml, account.username
|
||||||
summary xml, account.note
|
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
|
portable_contact xml, account
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -160,6 +169,7 @@ module AtomHelper
|
||||||
if stream_entry.target.object_type == :person
|
if stream_entry.target.object_type == :person
|
||||||
summary xml, stream_entry.target.content
|
summary xml, stream_entry.target.content
|
||||||
portable_contact xml, stream_entry.target
|
portable_contact xml, stream_entry.target
|
||||||
|
link_avatar xml, stream_entry.target
|
||||||
end
|
end
|
||||||
|
|
||||||
# Statuses have content
|
# Statuses have content
|
||||||
|
@ -177,6 +187,6 @@ module AtomHelper
|
||||||
private
|
private
|
||||||
|
|
||||||
def root_tag(xml, tag, &block)
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,16 +58,7 @@ class FollowRemoteAccountService < BaseService
|
||||||
|
|
||||||
def get_profile(xml, account)
|
def get_profile(xml, account)
|
||||||
author = xml.at_xpath('/xmlns:feed/xmlns:author')
|
author = xml.at_xpath('/xmlns:feed/xmlns:author')
|
||||||
|
update_remote_profile_service.(author, account)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def magic_key_to_pem(magic_key)
|
def magic_key_to_pem(magic_key)
|
||||||
|
@ -81,6 +72,10 @@ class FollowRemoteAccountService < BaseService
|
||||||
key.to_pem
|
key.to_pem
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_remote_profile_service
|
||||||
|
@update_remote_profile_service ||= UpdateRemoteProfileService.new
|
||||||
|
end
|
||||||
|
|
||||||
def http_client
|
def http_client
|
||||||
HTTP
|
HTTP
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,10 @@ class ProcessFeedService < BaseService
|
||||||
def call(body, account)
|
def call(body, account)
|
||||||
xml = Nokogiri::XML(body)
|
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|
|
xml.xpath('//xmlns:entry').each do |entry|
|
||||||
next unless [:note, :comment, :activity].includes? object_type(entry)
|
next unless [:note, :comment, :activity].includes? object_type(entry)
|
||||||
|
|
||||||
|
@ -126,4 +130,8 @@ class ProcessFeedService < BaseService
|
||||||
def process_mentions_service
|
def process_mentions_service
|
||||||
@process_mentions_service ||= ProcessMentionsService.new
|
@process_mentions_service ||= ProcessMentionsService.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_remote_profile_service
|
||||||
|
@update_remote_profile_service ||= UpdateRemoteProfileService.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,8 @@ class ProcessInteractionService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
if salmon.verify(envelope, account.keypair)
|
if salmon.verify(envelope, account.keypair)
|
||||||
|
update_remote_profile_service.(xml.at_xpath('/xmlns:entry/xmlns:author'), account)
|
||||||
|
|
||||||
case verb(xml)
|
case verb(xml)
|
||||||
when :follow
|
when :follow
|
||||||
follow!(account, target_account)
|
follow!(account, target_account)
|
||||||
|
@ -86,4 +88,8 @@ class ProcessInteractionService < BaseService
|
||||||
def process_feed_service
|
def process_feed_service
|
||||||
@process_feed_service ||= ProcessFeedService.new
|
@process_feed_service ||= ProcessFeedService.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_remote_profile_service
|
||||||
|
@update_remote_profile_service ||= UpdateRemoteProfileService.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
19
app/services/update_remote_profile_service.rb
Normal file
19
app/services/update_remote_profile_service.rb
Normal file
|
@ -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
|
|
@ -4,12 +4,13 @@ Nokogiri::XML::Builder.new do |xml|
|
||||||
title xml, @account.display_name
|
title xml, @account.display_name
|
||||||
subtitle xml, @account.note
|
subtitle xml, @account.note
|
||||||
updated_at xml, stream_updated_at
|
updated_at xml, stream_updated_at
|
||||||
|
logo xml, asset_url(@account.avatar.url(:medium))
|
||||||
|
|
||||||
author(xml) do
|
author(xml) do
|
||||||
include_author xml, @account
|
include_author xml, @account
|
||||||
end
|
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_self xml, atom_user_stream_url(id: @account.id)
|
||||||
link_hub xml, HUB_URL
|
link_hub xml, HUB_URL
|
||||||
link_salmon xml, salmon_url(@account)
|
link_salmon xml, salmon_url(@account)
|
||||||
|
|
|
@ -7,4 +7,4 @@
|
||||||
%span.num= status.favourites.count
|
%span.num= status.favourites.count
|
||||||
|
|
||||||
- if status.reply?
|
- 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'
|
||||||
|
|
|
@ -112,4 +112,12 @@ RSpec.describe AtomHelper, type: :helper do
|
||||||
describe '#include_entry' do
|
describe '#include_entry' do
|
||||||
pending
|
pending
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#link_avatar' do
|
||||||
|
pending
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#logo' do
|
||||||
|
pending
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,27 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ProfileHelper, type: :helper do
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue