Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - app/models/status.rb - db/schema.rb Both conflicts are caused by us having extra database columns.
This commit is contained in:
@ -63,13 +63,19 @@ module JsonLdHelper
|
||||
json.present? && json['id'] == uri ? json : nil
|
||||
end
|
||||
|
||||
def fetch_resource_without_id_validation(uri, on_behalf_of = nil)
|
||||
def fetch_resource_without_id_validation(uri, on_behalf_of = nil, raise_on_temporary_error = false)
|
||||
build_request(uri, on_behalf_of).perform do |response|
|
||||
unless response_successful?(response) || response_error_unsalvageable?(response) || !raise_on_temporary_error
|
||||
raise Mastodon::UnexpectedResponseError, response
|
||||
end
|
||||
return body_to_json(response.body_with_limit) if response.code == 200
|
||||
end
|
||||
# If request failed, retry without doing it on behalf of a user
|
||||
return if on_behalf_of.nil?
|
||||
build_request(uri).perform do |response|
|
||||
unless response_successful?(response) || response_error_unsalvageable?(response) || !raise_on_temporary_error
|
||||
raise Mastodon::UnexpectedResponseError, response
|
||||
end
|
||||
response.code == 200 ? body_to_json(response.body_with_limit) : nil
|
||||
end
|
||||
end
|
||||
@ -92,6 +98,14 @@ module JsonLdHelper
|
||||
|
||||
private
|
||||
|
||||
def response_successful?(response)
|
||||
(200...300).cover?(response.code)
|
||||
end
|
||||
|
||||
def response_error_unsalvageable?(response)
|
||||
(400...500).cover?(response.code) && response.code != 429
|
||||
end
|
||||
|
||||
def build_request(uri, on_behalf_of = nil)
|
||||
request = Request.new(:get, uri)
|
||||
request.on_behalf_of(on_behalf_of) if on_behalf_of
|
||||
|
@ -110,9 +110,19 @@ module StreamEntriesHelper
|
||||
I18n.t('statuses.content_warning', warning: status.spoiler_text)
|
||||
end
|
||||
|
||||
def poll_summary(status)
|
||||
return unless status.poll
|
||||
status.poll.options.map { |o| "[ ] #{o}" }.join("\n")
|
||||
end
|
||||
|
||||
def status_description(status)
|
||||
components = [[media_summary(status), status_text_summary(status)].reject(&:blank?).join(' · ')]
|
||||
components << status.text if status.spoiler_text.blank?
|
||||
|
||||
if status.spoiler_text.blank?
|
||||
components << status.text
|
||||
components << poll_summary(status)
|
||||
end
|
||||
|
||||
components.reject(&:blank?).join("\n\n")
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user