refetch profile if it's missing, comment out hydra stub for now because it breaks the specs
This commit is contained in:
parent
914e35dcad
commit
fbe91aba3a
4 changed files with 45 additions and 31 deletions
|
|
@ -85,8 +85,10 @@ class Person < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def name(opts = {})
|
def name(opts = {})
|
||||||
|
if self.profile.nil?
|
||||||
|
fix_profile
|
||||||
|
end
|
||||||
@name ||= Person.name_from_attrs(self.profile.first_name, self.profile.last_name, self.diaspora_handle)
|
@name ||= Person.name_from_attrs(self.profile.first_name, self.profile.last_name, self.diaspora_handle)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.name_from_attrs(first_name, last_name, diaspora_handle)
|
def self.name_from_attrs(first_name, last_name, diaspora_handle)
|
||||||
|
|
@ -169,15 +171,19 @@ class Person < ActiveRecord::Base
|
||||||
#hcard_profile = HCard.find profile.hcard.first[:href]
|
#hcard_profile = HCard.find profile.hcard.first[:href]
|
||||||
Rails.logger.info("event=webfinger_marshal valid=#{new_person.valid?} target=#{new_person.diaspora_handle}")
|
Rails.logger.info("event=webfinger_marshal valid=#{new_person.valid?} target=#{new_person.diaspora_handle}")
|
||||||
new_person.url = hcard[:url]
|
new_person.url = hcard[:url]
|
||||||
new_person.profile = Profile.new(:first_name => hcard[:given_name],
|
new_person.assign_new_profile_from_hcard(hcard)
|
||||||
|
new_person.save!
|
||||||
|
new_person.profile.save!
|
||||||
|
new_person
|
||||||
|
end
|
||||||
|
|
||||||
|
def assign_new_profile_from_hcard(hcard)
|
||||||
|
self.profile = Profile.new(:first_name => hcard[:given_name],
|
||||||
:last_name => hcard[:family_name],
|
:last_name => hcard[:family_name],
|
||||||
:image_url => hcard[:photo],
|
:image_url => hcard[:photo],
|
||||||
:image_url_medium => hcard[:photo_medium],
|
:image_url_medium => hcard[:photo_medium],
|
||||||
:image_url_small => hcard[:photo_small],
|
:image_url_small => hcard[:photo_small],
|
||||||
:searchable => hcard[:searchable])
|
:searchable => hcard[:searchable])
|
||||||
new_person.save!
|
|
||||||
new_person.profile.save!
|
|
||||||
new_person
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote?
|
def remote?
|
||||||
|
|
@ -224,4 +230,9 @@ class Person < ActiveRecord::Base
|
||||||
def remove_all_traces
|
def remove_all_traces
|
||||||
Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy}
|
Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fix_profile
|
||||||
|
Webfinger.new(self.diaspora_handle).fetch
|
||||||
|
self.reload
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,21 @@ class Webfinger
|
||||||
begin
|
begin
|
||||||
person = Person.by_account_identifier(@account)
|
person = Person.by_account_identifier(@account)
|
||||||
if person
|
if person
|
||||||
|
if person.profile
|
||||||
Rails.logger.info("event=webfinger status=success route=local target=#{@account}")
|
Rails.logger.info("event=webfinger status=success route=local target=#{@account}")
|
||||||
return person
|
return person
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
profile_url = get_xrd
|
profile_url = get_xrd
|
||||||
webfinger_profile = get_webfinger_profile(profile_url)
|
webfinger_profile = get_webfinger_profile(profile_url)
|
||||||
|
if person
|
||||||
|
person.assign_new_profile_from_hcard(get_hcard(webfinger_profile))
|
||||||
|
fingered_person = person
|
||||||
|
else
|
||||||
fingered_person = make_person_from_webfinger(webfinger_profile)
|
fingered_person = make_person_from_webfinger(webfinger_profile)
|
||||||
|
end
|
||||||
|
|
||||||
if fingered_person
|
if fingered_person
|
||||||
Rails.logger.info("event=webfinger status=success route=remote target=#{@account}")
|
Rails.logger.info("event=webfinger status=success route=remote target=#{@account}")
|
||||||
fingered_person
|
fingered_person
|
||||||
|
|
@ -69,7 +77,7 @@ class Webfinger
|
||||||
return http.body
|
return http.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_person_from_webfinger(webfinger_profile)
|
def get_hcard(webfinger_profile)
|
||||||
unless webfinger_profile.strip == ""
|
unless webfinger_profile.strip == ""
|
||||||
|
|
||||||
wf_profile = WebfingerProfile.new(@account, webfinger_profile)
|
wf_profile = WebfingerProfile.new(@account, webfinger_profile)
|
||||||
|
|
@ -80,7 +88,15 @@ class Webfinger
|
||||||
return I18n.t('webfinger.hcard_fetch_failed', :account => @account)
|
return I18n.t('webfinger.hcard_fetch_failed', :account => @account)
|
||||||
end
|
end
|
||||||
|
|
||||||
card = HCard.build hcard.body
|
HCard.build hcard.body
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_person_from_webfinger(webfinger_profile)
|
||||||
|
card = get_hcard(webfinger_profile)
|
||||||
|
if card
|
||||||
p = Person.create_from_webfinger(wf_profile, card)
|
p = Person.create_from_webfinger(wf_profile, card)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,3 @@ module HelperMethods
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
class Typhoeus::Hydra
|
|
||||||
def initialize
|
|
||||||
end
|
|
||||||
|
|
||||||
def queue(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def run
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
class Typhoeus::Hydra
|
#class Typhoeus::Hydra
|
||||||
def initialize
|
# def initialize
|
||||||
end
|
# end
|
||||||
|
|
||||||
def queue(*args)
|
# def queue(*args)
|
||||||
end
|
# end
|
||||||
|
|
||||||
def run
|
# def run
|
||||||
end
|
# end
|
||||||
end
|
#end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue