Merge upstream!! #64 <3 <3
This commit is contained in:
@@ -54,7 +54,7 @@ class FanOutOnWriteService < BaseService
|
||||
end
|
||||
|
||||
def render_anonymous_payload(status)
|
||||
@payload = InlineRenderer.render(status, nil, 'api/v1/statuses/show')
|
||||
@payload = InlineRenderer.render(status, nil, :status)
|
||||
@payload = Oj.dump(event: :update, payload: @payload)
|
||||
end
|
||||
|
||||
|
@@ -20,6 +20,10 @@ class FetchAtomService < BaseService
|
||||
process_html(fetch(url))
|
||||
rescue OpenSSL::SSL::SSLError => e
|
||||
Rails.logger.debug "SSL error: #{e}"
|
||||
nil
|
||||
rescue HTTP::ConnectionError => e
|
||||
Rails.logger.debug "HTTP ConnectionError: #{e}"
|
||||
nil
|
||||
end
|
||||
|
||||
private
|
||||
|
@@ -18,6 +18,8 @@ class FetchLinkCardService < BaseService
|
||||
return if res.code != 200 || res.mime_type != 'text/html'
|
||||
|
||||
attempt_opengraph(card, url) unless attempt_oembed(card, url)
|
||||
rescue HTTP::ConnectionError, OpenSSL::SSL::SSLError
|
||||
nil
|
||||
end
|
||||
|
||||
private
|
||||
@@ -82,7 +84,13 @@ class FetchLinkCardService < BaseService
|
||||
|
||||
return if response.code != 200 || response.mime_type != 'text/html'
|
||||
|
||||
page = Nokogiri::HTML(response.to_s)
|
||||
html = response.to_s
|
||||
|
||||
detector = CharlockHolmes::EncodingDetector.new
|
||||
detector.strip_tags = true
|
||||
|
||||
guess = detector.detect(html, response.charset)
|
||||
page = Nokogiri::HTML(html, nil, guess&.fetch(:encoding))
|
||||
|
||||
card.type = :link
|
||||
card.title = meta_property(page, 'og:title') || page.at_xpath('//title')&.content
|
||||
|
@@ -32,5 +32,8 @@ class FetchRemoteAccountService < BaseService
|
||||
rescue Nokogiri::XML::XPath::SyntaxError
|
||||
Rails.logger.debug 'Invalid XML or missing namespace'
|
||||
nil
|
||||
rescue Goldfinger::NotFoundError, Goldfinger::Error
|
||||
Rails.logger.debug 'Exceptions related to Goldfinger occurs'
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
@@ -5,6 +5,9 @@ class FetchRemoteResourceService < BaseService
|
||||
|
||||
def call(url)
|
||||
@url = url
|
||||
|
||||
return process_local_url if local_url?
|
||||
|
||||
process_url unless fetched_atom_feed.nil?
|
||||
end
|
||||
|
||||
@@ -38,4 +41,29 @@ class FetchRemoteResourceService < BaseService
|
||||
def xml_data
|
||||
@_xml_data ||= Nokogiri::XML(body, nil, 'utf-8')
|
||||
end
|
||||
|
||||
def local_url?
|
||||
TagManager.instance.local_url?(@url)
|
||||
end
|
||||
|
||||
def process_local_url
|
||||
recognized_params = Rails.application.routes.recognize_path(@url)
|
||||
|
||||
return unless recognized_params[:action] == 'show'
|
||||
|
||||
if recognized_params[:controller] == 'stream_entries'
|
||||
status = StreamEntry.find_by(id: recognized_params[:id])&.status
|
||||
check_local_status(status)
|
||||
elsif recognized_params[:controller] == 'statuses'
|
||||
status = Status.find_by(id: recognized_params[:id])
|
||||
check_local_status(status)
|
||||
elsif recognized_params[:controller] == 'accounts'
|
||||
Account.find_local(recognized_params[:username])
|
||||
end
|
||||
end
|
||||
|
||||
def check_local_status(status)
|
||||
return if status.nil?
|
||||
status if status.public_visibility? || status.unlisted_visibility?
|
||||
end
|
||||
end
|
||||
|
@@ -33,6 +33,9 @@ class FetchRemoteStatusService < BaseService
|
||||
rescue Nokogiri::XML::XPath::SyntaxError
|
||||
Rails.logger.debug 'Invalid XML or missing namespace'
|
||||
nil
|
||||
rescue Goldfinger::NotFoundError, Goldfinger::Error
|
||||
Rails.logger.debug 'Exceptions related to Goldfinger occurs'
|
||||
nil
|
||||
end
|
||||
|
||||
def confirmed_domain?(domain, account)
|
||||
|
@@ -60,7 +60,7 @@ class NotifyService < BaseService
|
||||
def create_notification
|
||||
@notification.save!
|
||||
return unless @notification.browserable?
|
||||
Redis.current.publish("timeline:#{@recipient.id}", Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, 'api/v1/notifications/show')))
|
||||
Redis.current.publish("timeline:#{@recipient.id}", Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, :notification)))
|
||||
end
|
||||
|
||||
def send_email
|
||||
|
@@ -13,21 +13,16 @@ class PrecomputeFeedService < BaseService
|
||||
attr_reader :account
|
||||
|
||||
def populate_feed
|
||||
redis.pipelined do
|
||||
statuses.each do |status|
|
||||
process_status(status)
|
||||
end
|
||||
pairs = statuses.reverse_each.lazy.reject(&method(:status_filtered?)).map(&method(:process_status)).to_a
|
||||
|
||||
redis.pipelined do
|
||||
redis.zadd(account_home_key, pairs) if pairs.any?
|
||||
redis.del("account:#{@account.id}:regeneration")
|
||||
end
|
||||
end
|
||||
|
||||
def process_status(status)
|
||||
add_status_to_feed(status) unless status_filtered?(status)
|
||||
end
|
||||
|
||||
def add_status_to_feed(status)
|
||||
redis.zadd(account_home_key, status.id, status.reblog? ? status.reblog_of_id : status.id)
|
||||
[status.id, status.reblog? ? status.reblog_of_id : status.id]
|
||||
end
|
||||
|
||||
def status_filtered?(status)
|
||||
|
@@ -20,8 +20,6 @@ class ProcessFeedService < BaseService
|
||||
end
|
||||
|
||||
class ProcessEntry
|
||||
include AuthorExtractor
|
||||
|
||||
def call(xml, account)
|
||||
@account = account
|
||||
@xml = xml
|
||||
@@ -42,7 +40,7 @@ class ProcessFeedService < BaseService
|
||||
private
|
||||
|
||||
def create_status
|
||||
if redis.exists("delete_upon_arrival:#{id}")
|
||||
if redis.exists("delete_upon_arrival:#{@account.id}:#{id}")
|
||||
Rails.logger.debug "Delete for status #{id} was queued, ignoring"
|
||||
return
|
||||
end
|
||||
@@ -99,15 +97,13 @@ class ProcessFeedService < BaseService
|
||||
|
||||
def delete_status
|
||||
Rails.logger.debug "Deleting remote status #{id}"
|
||||
status = Status.find_by(uri: id)
|
||||
status = Status.find_by(uri: id, account: @account)
|
||||
|
||||
if status.nil?
|
||||
redis.setex("delete_upon_arrival:#{id}", 6 * 3_600, id)
|
||||
redis.setex("delete_upon_arrival:#{@account.id}:#{id}", 6 * 3_600, id)
|
||||
else
|
||||
RemoveStatusService.new.call(status)
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
def skip_unsupported_type?
|
||||
@@ -128,18 +124,7 @@ class ProcessFeedService < BaseService
|
||||
|
||||
return [status, false] unless status.nil?
|
||||
|
||||
# If status embeds an author, find that author
|
||||
# If that author cannot be found, don't record the status (do not misattribute)
|
||||
if account?(entry)
|
||||
begin
|
||||
account = author_from_xml(entry)
|
||||
return [nil, false] if account.nil?
|
||||
rescue Goldfinger::Error
|
||||
return [nil, false]
|
||||
end
|
||||
else
|
||||
account = @account
|
||||
end
|
||||
account = @account
|
||||
|
||||
return [nil, false] if account.suspended?
|
||||
|
||||
|
Reference in New Issue
Block a user