Merge remote-tracking branch 'parent/main' into upstream-20241101
This commit is contained in:
commit
1c1f76697b
200 changed files with 1931 additions and 741 deletions
|
@ -20,9 +20,9 @@ class ActivityPub::Activity
|
|||
end
|
||||
|
||||
class << self
|
||||
def factory(json, account, **options)
|
||||
def factory(json, account, **)
|
||||
@json = json
|
||||
klass&.new(json, account, **options)
|
||||
klass&.new(json, account, **)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -64,6 +64,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
ApplicationRecord.transaction do
|
||||
@status = Status.create!(@params)
|
||||
attach_tags(@status)
|
||||
attach_counts(@status)
|
||||
end
|
||||
|
||||
resolve_thread(@status)
|
||||
|
@ -233,6 +234,18 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
end
|
||||
end
|
||||
|
||||
def attach_counts(status)
|
||||
likes = @status_parser.favourites_count
|
||||
shares = @status_parser.reblogs_count
|
||||
return if likes.nil? && shares.nil?
|
||||
|
||||
status.status_stat.tap do |status_stat|
|
||||
status_stat.untrusted_reblogs_count = shares unless shares.nil?
|
||||
status_stat.untrusted_favourites_count = likes unless likes.nil?
|
||||
status_stat.save if status_stat.changed?
|
||||
end
|
||||
end
|
||||
|
||||
def process_tags
|
||||
return if @object['tag'].nil?
|
||||
|
||||
|
|
|
@ -124,6 +124,14 @@ class ActivityPub::Parser::StatusParser
|
|||
lang.presence && NORMALIZED_LOCALE_NAMES.fetch(lang.downcase.to_sym, lang)
|
||||
end
|
||||
|
||||
def favourites_count
|
||||
@object.dig(:likes, :totalItems)
|
||||
end
|
||||
|
||||
def reblogs_count
|
||||
@object.dig(:shares, :totalItems)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def raw_language_code
|
||||
|
|
|
@ -7,7 +7,7 @@ class AnnualReport::CommonlyInteractedWithAccounts < AnnualReport::Source
|
|||
{
|
||||
commonly_interacted_with_accounts: commonly_interacted_with_accounts.map do |(account_id, count)|
|
||||
{
|
||||
account_id: account_id,
|
||||
account_id: account_id.to_s,
|
||||
count: count,
|
||||
}
|
||||
end,
|
||||
|
|
|
@ -7,7 +7,7 @@ class AnnualReport::MostRebloggedAccounts < AnnualReport::Source
|
|||
{
|
||||
most_reblogged_accounts: most_reblogged_accounts.map do |(account_id, count)|
|
||||
{
|
||||
account_id: account_id,
|
||||
account_id: account_id.to_s,
|
||||
count: count,
|
||||
}
|
||||
end,
|
||||
|
|
|
@ -8,9 +8,9 @@ class AnnualReport::TopStatuses < AnnualReport::Source
|
|||
|
||||
{
|
||||
top_statuses: {
|
||||
by_reblogs: top_reblogs,
|
||||
by_favourites: top_favourites,
|
||||
by_replies: top_replies,
|
||||
by_reblogs: top_reblogs&.to_s,
|
||||
by_favourites: top_favourites&.to_s,
|
||||
by_replies: top_replies&.to_s,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
|
|
@ -77,10 +77,22 @@ class AttachmentBatch
|
|||
when :fog
|
||||
logger.debug { "Deleting #{attachment.path(style)}" }
|
||||
|
||||
retries = 0
|
||||
begin
|
||||
attachment.send(:directory).files.new(key: attachment.path(style)).destroy
|
||||
rescue Fog::Storage::OpenStack::NotFound
|
||||
# Ignore failure to delete a file that has already been deleted
|
||||
rescue Fog::OpenStack::Storage::NotFound
|
||||
logger.debug "Will ignore because file is not found #{attachment.path(style)}"
|
||||
rescue => e
|
||||
retries += 1
|
||||
|
||||
if retries < MAX_RETRY
|
||||
logger.debug "Retry #{retries}/#{MAX_RETRY} after #{e.message}"
|
||||
sleep 2**retries
|
||||
retry
|
||||
else
|
||||
logger.error "Batch deletion from fog failed after #{e.message}"
|
||||
raise e
|
||||
end
|
||||
end
|
||||
when :azure
|
||||
logger.debug { "Deleting #{attachment.path(style)}" }
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RSS::Element
|
||||
def self.with(*args, &block)
|
||||
new(*args).tap(&block).to_element
|
||||
def self.with(*, &block)
|
||||
new(*).tap(&block).to_element
|
||||
end
|
||||
|
||||
def create_element(name, content = nil)
|
||||
|
|
|
@ -34,21 +34,26 @@ class TextFormatter
|
|||
def to_s
|
||||
return ''.html_safe if text.blank?
|
||||
|
||||
html = rewrite do |entity|
|
||||
if entity[:url]
|
||||
link_to_url(entity)
|
||||
elsif entity[:hashtag]
|
||||
link_to_hashtag(entity)
|
||||
elsif entity[:screen_name]
|
||||
link_to_mention(entity)
|
||||
html = nil
|
||||
MastodonOTELTracer.in_span('TextFormatter#to_s extract_and_rewrite') do
|
||||
html = rewrite do |entity|
|
||||
if entity[:url]
|
||||
link_to_url(entity)
|
||||
elsif entity[:hashtag]
|
||||
link_to_hashtag(entity)
|
||||
elsif entity[:screen_name]
|
||||
link_to_mention(entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# line first letter for blockquote
|
||||
html = markdownify(html.gsub(/^>/, '>')) if markdown?
|
||||
MastodonOTELTracer.in_span('TextFormatter#to_s simple_format') do
|
||||
# line first letter for blockquote
|
||||
html = markdownify(html.gsub(/^>/, '>')) if markdown?
|
||||
|
||||
html = simple_format(html, {}, sanitize: false).delete("\n") if !markdown? && multiline?
|
||||
html = html.delete("\n")
|
||||
html = simple_format(html, {}, sanitize: false).delete("\n") if !markdown? && multiline?
|
||||
html = html.delete("\n")
|
||||
end
|
||||
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
@ -98,48 +103,54 @@ class TextFormatter
|
|||
end
|
||||
|
||||
def link_to_url(entity)
|
||||
TextFormatter.shortened_link(entity[:url], rel_me: with_rel_me?)
|
||||
MastodonOTELTracer.in_span('TextFormatter#link_to_url') do
|
||||
TextFormatter.shortened_link(entity[:url], rel_me: with_rel_me?)
|
||||
end
|
||||
end
|
||||
|
||||
def link_to_hashtag(entity)
|
||||
hashtag = entity[:hashtag]
|
||||
url = tag_url(hashtag)
|
||||
MastodonOTELTracer.in_span('TextFormatter#link_to_hashtag') do
|
||||
hashtag = entity[:hashtag]
|
||||
url = tag_url(hashtag)
|
||||
|
||||
<<~HTML.squish
|
||||
<a href="#{h(url)}" class="mention hashtag" rel="tag">#<span>#{h(hashtag)}</span></a>
|
||||
HTML
|
||||
<<~HTML.squish
|
||||
<a href="#{h(url)}" class="mention hashtag" rel="tag">#<span>#{h(hashtag)}</span></a>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
||||
def link_to_mention(entity)
|
||||
username, domain = entity[:screen_name].split('@')
|
||||
domain = nil if local_domain?(domain)
|
||||
account = nil
|
||||
MastodonOTELTracer.in_span('TextFormatter#link_to_mention') do
|
||||
username, domain = entity[:screen_name].split('@')
|
||||
domain = nil if local_domain?(domain)
|
||||
account = nil
|
||||
|
||||
if preloaded_accounts?
|
||||
same_username_hits = 0
|
||||
if preloaded_accounts?
|
||||
same_username_hits = 0
|
||||
|
||||
preloaded_accounts.each do |other_account|
|
||||
same_username = other_account.username.casecmp(username).zero?
|
||||
same_domain = other_account.domain.nil? ? domain.nil? : other_account.domain.casecmp(domain)&.zero?
|
||||
preloaded_accounts.each do |other_account|
|
||||
same_username = other_account.username.casecmp(username).zero?
|
||||
same_domain = other_account.domain.nil? ? domain.nil? : other_account.domain.casecmp(domain)&.zero?
|
||||
|
||||
if same_username && !same_domain
|
||||
same_username_hits += 1
|
||||
elsif same_username && same_domain
|
||||
account = other_account
|
||||
if same_username && !same_domain
|
||||
same_username_hits += 1
|
||||
elsif same_username && same_domain
|
||||
account = other_account
|
||||
end
|
||||
end
|
||||
else
|
||||
account = entity_cache.mention(username, domain)
|
||||
end
|
||||
else
|
||||
account = entity_cache.mention(username, domain)
|
||||
|
||||
return "@#{h(entity[:screen_name])}" if account.nil?
|
||||
|
||||
url = ActivityPub::TagManager.instance.url_for(account)
|
||||
display_username = same_username_hits&.positive? || with_domains? ? account.pretty_acct : account.username
|
||||
|
||||
<<~HTML.squish
|
||||
<span class="h-card" translate="no"><a href="#{h(url)}" class="u-url mention">@<span>#{h(display_username)}</span></a></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
return "@#{h(entity[:screen_name])}" if account.nil?
|
||||
|
||||
url = ActivityPub::TagManager.instance.url_for(account)
|
||||
display_username = same_username_hits&.positive? || with_domains? ? account.pretty_acct : account.username
|
||||
|
||||
<<~HTML.squish
|
||||
<span class="h-card" translate="no"><a href="#{h(url)}" class="u-url mention">@<span>#{h(display_username)}</span></a></span>
|
||||
HTML
|
||||
end
|
||||
|
||||
def entity_cache
|
||||
|
|
|
@ -42,8 +42,8 @@ class TranslationService::DeepL < TranslationService
|
|||
subtags.join('-')
|
||||
end
|
||||
|
||||
def request(verb, path, **options)
|
||||
req = Request.new(verb, "#{base_url}#{path}", **options)
|
||||
def request(verb, path, **)
|
||||
req = Request.new(verb, "#{base_url}#{path}", **)
|
||||
req.add_headers(Authorization: "DeepL-Auth-Key #{@api_key}")
|
||||
req.perform do |res|
|
||||
case res.code
|
||||
|
|
|
@ -27,8 +27,8 @@ class TranslationService::LibreTranslate < TranslationService
|
|||
|
||||
private
|
||||
|
||||
def request(verb, path, **options)
|
||||
req = Request.new(verb, "#{@base_url}#{path}", allow_local: true, **options)
|
||||
def request(verb, path, **)
|
||||
req = Request.new(verb, "#{@base_url}#{path}", allow_local: true, **)
|
||||
req.add_headers('Content-Type': 'application/json')
|
||||
req.perform do |res|
|
||||
case res.code
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue