forked from diaspora/diaspora
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
9 changed files
with
93 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module Diaspora | ||
module Fetcher | ||
require 'diaspora/fetcher/public' | ||
require 'diaspora/fetcher/single' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Diaspora | ||
module Fetcher | ||
module Single | ||
module_function | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# 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 = Webfinger.new(author_id).fetch | ||
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 = 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
don't you have to specify a symbol to
module_function
?