refetch profile if it's missing, comment out hydra stub for now because it breaks the specs

This commit is contained in:
MrZYX 2011-04-09 15:09:34 +02:00
parent 914e35dcad
commit fbe91aba3a
4 changed files with 45 additions and 31 deletions

View file

@ -85,8 +85,10 @@ class Person < ActiveRecord::Base
end
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)
end
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]
Rails.logger.info("event=webfinger_marshal valid=#{new_person.valid?} target=#{new_person.diaspora_handle}")
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],
:image_url => hcard[:photo],
:image_url_medium => hcard[:photo_medium],
:image_url_small => hcard[:photo_small],
:searchable => hcard[:searchable])
new_person.save!
new_person.profile.save!
new_person
end
def remote?
@ -224,4 +230,9 @@ class Person < ActiveRecord::Base
def remove_all_traces
Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy}
end
def fix_profile
Webfinger.new(self.diaspora_handle).fetch
self.reload
end
end

View file

@ -16,13 +16,21 @@ class Webfinger
begin
person = Person.by_account_identifier(@account)
if person
if person.profile
Rails.logger.info("event=webfinger status=success route=local target=#{@account}")
return person
end
end
profile_url = get_xrd
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)
end
if fingered_person
Rails.logger.info("event=webfinger status=success route=remote target=#{@account}")
fingered_person
@ -69,7 +77,7 @@ class Webfinger
return http.body
end
def make_person_from_webfinger(webfinger_profile)
def get_hcard(webfinger_profile)
unless webfinger_profile.strip == ""
wf_profile = WebfingerProfile.new(@account, webfinger_profile)
@ -80,7 +88,15 @@ class Webfinger
return I18n.t('webfinger.hcard_fetch_failed', :account => @account)
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)
end
end

View file

@ -17,16 +17,3 @@ module HelperMethods
result
end
end
class Typhoeus::Hydra
def initialize
end
def queue(*args)
end
def run
end
end

View file

@ -1,11 +1,11 @@
class Typhoeus::Hydra
def initialize
end
#class Typhoeus::Hydra
# def initialize
# end
def queue(*args)
end
# def queue(*args)
# end
def run
end
end
# def run
# end
#end