diff options
author | Jonne Haß <me@jhass.eu> | 2014-09-07 01:19:57 +0400 |
---|---|---|
committer | Jonne Haß <me@jhass.eu> | 2014-09-07 12:47:47 +0400 |
commit | 777e3123d6968fe4f6c5c2f4032220918c59d3de (patch) | |
tree | c97399c554264464d4d7ac8d5d282774cc9458cb /app | |
parent | 9c88fde82139ee8a094932e35fa49c4e00b6fb0a (diff) |
Try fetching missing parent of relayables
* Extract post fetching logic from Reshare into
its own module
* raise proper error message when fetching fails
* raise proper error message when parent is still missing
We can't skip fetch failures or missing parents and
still need to retry them in case we're sent the parent
later on
Diffstat (limited to 'app')
-rw-r--r-- | app/models/reshare.rb | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 5bb5326d5..33581d05e 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -74,35 +74,16 @@ class Reshare < Post private def after_parse - root_author = Webfinger.new(@root_diaspora_id).fetch - root_author.save! unless root_author.persisted? - - return if Post.exists?(:guid => self.root_guid) - - fetched_post = self.class.fetch_post(root_author, self.root_guid) - - if fetched_post - #Why are we checking for this? - 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!" + if root.blank? + self.root = Diaspora::Fetcher::Single.find_or_fetch_from_remote root_guid, @root_diaspora_id do |fetched_post, author| + # why do we check this? + if fetched_post.diaspora_handle != author.diaspora_handle + raise Diaspora::PostNotFetchable, "Diaspora ID (#{fetched_post.diaspora_handle}) in the root does not match the Diaspora ID (#{author.diaspora_handle}) specified in the reshare!" + end end - - fetched_post.save! end end - # Fetch a remote public post, used for receiving reshares of unknown posts - # @param [Person] author the remote post's author - # @param [String] guid the remote post's guid - # @return [Post] an unsaved remote post or false if the post was not found - def self.fetch_post author, guid - url = author.url + "/p/#{guid}.xml" - response = Faraday.get(url) - return false if response.status == 404 # Old pod, friendika - raise "Failed to get #{url}" unless response.success? # Other error, N/A for example - Diaspora::Parser.from_xml(response.body) - end - def root_must_be_public if self.root && !self.root.public errors[:base] << "Only posts which are public may be reshared." |