remove post fetcher
This commit is contained in:
parent
51aca4506f
commit
c8c489eafd
3 changed files with 0 additions and 53 deletions
|
|
@ -65,17 +65,6 @@ class Reshare < Post
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def after_parse
|
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def root_must_be_public
|
def root_must_be_public
|
||||||
if self.root && !self.root.public
|
if self.root && !self.root.public
|
||||||
errors[:base] << "Only posts which are public may be reshared."
|
errors[:base] << "Only posts which are public may be reshared."
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
module Diaspora
|
module Diaspora
|
||||||
module Fetcher
|
module Fetcher
|
||||||
require 'diaspora/fetcher/public'
|
require 'diaspora/fetcher/public'
|
||||||
require 'diaspora/fetcher/single'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
module Diaspora
|
|
||||||
module Fetcher
|
|
||||||
module Single
|
|
||||||
module_function
|
|
||||||
|
|
||||||
# Fetch and store a remote public post
|
|
||||||
# @param [String] guid the remote posts guid
|
|
||||||
# @param [String] author_id Diaspora ID of a user known to have the post,
|
|
||||||
# preferably the author
|
|
||||||
# @yield [Post, Person] If a block is given it is yielded the post
|
|
||||||
# and the author prior save
|
|
||||||
# @return a saved post
|
|
||||||
def find_or_fetch_from_remote guid, author_id
|
|
||||||
post = Post.where(guid: guid).first
|
|
||||||
return post if post
|
|
||||||
|
|
||||||
post_author = Person.find_or_fetch_by_identifier(author_id)
|
|
||||||
post_author.save! unless post_author.persisted?
|
|
||||||
|
|
||||||
if fetched_post = fetch_post(post_author, guid)
|
|
||||||
yield fetched_post, post_author if block_given?
|
|
||||||
raise Diaspora::PostNotFetchable unless fetched_post.save
|
|
||||||
end
|
|
||||||
|
|
||||||
fetched_post
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fetch a remote public post, used for receiving of unknown public 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 fetch_post author, guid
|
|
||||||
url = URI.join(author.url, "/p/#{guid}.xml")
|
|
||||||
response = Faraday.get(url)
|
|
||||||
raise Diaspora::PostNotFetchable if response.status == 404 # Old pod, Friendika, deleted
|
|
||||||
raise "Failed to get #{url}" unless response.success? # Other error, N/A for example
|
|
||||||
Diaspora::Parser.from_xml(response.body)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
Reference in a new issue