diff options
author | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-23 01:38:56 +0400 |
---|---|---|
committer | Raphael Sofaer <raphael@joindiaspora.com> | 2011-07-23 01:38:56 +0400 |
commit | 5a12636967703521025625d27f4a1b1f2182bcf4 (patch) | |
tree | b05abbb281bce3935bc1141b52c38f81c8f69843 /app | |
parent | 4b1d5b772d4d812c231dbd713c5dcf9197b28002 (diff) |
Clarify Reshare#after_parse
Diffstat (limited to 'app')
-rw-r--r-- | app/models/reshare.rb | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 9ba63bcd9..cb1cbad64 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -40,23 +40,20 @@ class Reshare < Post root_author = Webfinger.new(@root_diaspora_id).fetch root_author.save! - local_post = Post.where(:guid => @root_guid).select('id').first - - unless local_post && self.root_id = local_post.id - received_post = self.class.fetch_post(root_author, @root_guid) - - unless post = received_post.class.where(:guid => received_post.guid).first - post = received_post - - if root_author.diaspora_handle != post.diaspora_handle - raise "Diaspora ID (#{post.diaspora_handle}) in the root does not match the Diaspora ID (#{root_author.diaspora_handle}) specified in the reshare!" - end + if local_post = Post.where(:guid => @root_guid).select('id').first + self.root_id = local_post.id + return + else + fetched_post = self.class.fetch_post(root_author, @root_guid) - post.author_id = root_author.id - post.save! + if root_author.diaspora_handle != fetched_post.diaspora_handle + raise "Diaspora ID (#{fetched_post.diaspora_handle}) in the root does not match the Diaspora ID (#{root_author.diaspora_handle}) specified in the reshare!" end - self.root_id = post.id + fetched_post.author_id = root_author.id + fetched_post.save! + + self.root_id = fetched_post.id end end @@ -65,7 +62,7 @@ class Reshare < Post # @param [String] guid the remote post's guid # @return [Post] an unsaved remote post def self.fetch_post author, guid - response = Faraday.get(root_author.url + "/p/#{@root_guid}.xml") + response = Faraday.get(author.url + "/p/#{guid}.xml") Diaspora::Parser.from_xml(response.body) end |