Merge remote-tracking branch 'parent/main' into upstream-20241006
This commit is contained in:
commit
66bed31dbe
226 changed files with 2688 additions and 1846 deletions
|
@ -4,6 +4,6 @@ class FilteredNotificationCleanupWorker
|
|||
include Sidekiq::Worker
|
||||
|
||||
def perform(account_id, from_account_id)
|
||||
Notification.where(account_id: account_id, from_account_id: from_account_id, filtered: true).reorder(nil).in_batches(order: :desc).delete_all
|
||||
Notification.where(account_id: account_id, from_account_id: from_account_id, filtered: true).in_batches(order: :desc).delete_all
|
||||
end
|
||||
end
|
||||
|
|
37
app/workers/mention_resolve_worker.rb
Normal file
37
app/workers/mention_resolve_worker.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MentionResolveWorker
|
||||
include Sidekiq::Worker
|
||||
include ExponentialBackoff
|
||||
include JsonLdHelper
|
||||
|
||||
sidekiq_options queue: 'pull', retry: 7
|
||||
|
||||
def perform(status_id, uri, options = {})
|
||||
status = Status.find_by(id: status_id)
|
||||
return if status.nil?
|
||||
|
||||
account = account_from_uri(uri)
|
||||
account = ActivityPub::FetchRemoteAccountService.new.call(uri, request_id: options[:request_id]) if account.nil?
|
||||
|
||||
return if account.nil?
|
||||
|
||||
status.mentions.create!(account: account, silent: false)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# Do nothing
|
||||
rescue Mastodon::UnexpectedResponseError => e
|
||||
response = e.response
|
||||
|
||||
if response_error_unsalvageable?(response)
|
||||
# Give up
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def account_from_uri(uri)
|
||||
ActivityPub::TagManager.instance.uri_to_resource(uri, Account)
|
||||
end
|
||||
end
|
|
@ -16,7 +16,7 @@ class Scheduler::UserCleanupScheduler
|
|||
private
|
||||
|
||||
def clean_unconfirmed_accounts!
|
||||
User.unconfirmed.where(confirmation_sent_at: ..UNCONFIRMED_ACCOUNTS_MAX_AGE_DAYS.days.ago).reorder(nil).find_in_batches do |batch|
|
||||
User.unconfirmed.where(confirmation_sent_at: ..UNCONFIRMED_ACCOUNTS_MAX_AGE_DAYS.days.ago).find_in_batches do |batch|
|
||||
# We have to do it separately because of missing database constraints
|
||||
AccountModerationNote.where(target_account_id: batch.map(&:account_id)).delete_all
|
||||
Account.where(id: batch.map(&:account_id)).delete_all
|
||||
|
|
|
@ -16,10 +16,10 @@ class Web::PushNotificationWorker
|
|||
# in the meantime, so we have to double-check before proceeding
|
||||
return unless @notification.activity.present? && @subscription.pushable?(@notification)
|
||||
|
||||
payload = @subscription.encrypt(push_notification_json)
|
||||
payload = web_push_request.encrypt(push_notification_json)
|
||||
|
||||
request_pool.with(@subscription.audience) do |http_client|
|
||||
request = Request.new(:post, @subscription.endpoint, body: payload.fetch(:ciphertext), http_client: http_client)
|
||||
request_pool.with(web_push_request.audience) do |http_client|
|
||||
request = Request.new(:post, web_push_request.endpoint, body: payload.fetch(:ciphertext), http_client: http_client)
|
||||
|
||||
request.add_headers(
|
||||
'Content-Type' => 'application/octet-stream',
|
||||
|
@ -27,8 +27,8 @@ class Web::PushNotificationWorker
|
|||
'Urgency' => URGENCY,
|
||||
'Content-Encoding' => 'aesgcm',
|
||||
'Encryption' => "salt=#{Webpush.encode64(payload.fetch(:salt)).delete('=')}",
|
||||
'Crypto-Key' => "dh=#{Webpush.encode64(payload.fetch(:server_public_key)).delete('=')};#{@subscription.crypto_key_header}",
|
||||
'Authorization' => @subscription.authorization_header
|
||||
'Crypto-Key' => "dh=#{Webpush.encode64(payload.fetch(:server_public_key)).delete('=')};#{web_push_request.crypto_key_header}",
|
||||
'Authorization' => web_push_request.authorization_header
|
||||
)
|
||||
|
||||
request.perform do |response|
|
||||
|
@ -50,17 +50,27 @@ class Web::PushNotificationWorker
|
|||
|
||||
private
|
||||
|
||||
def push_notification_json
|
||||
json = I18n.with_locale(@subscription.locale.presence || I18n.default_locale) do
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
@notification,
|
||||
serializer: Web::NotificationSerializer,
|
||||
scope: @subscription,
|
||||
scope_name: :current_push_subscription
|
||||
).as_json
|
||||
end
|
||||
def web_push_request
|
||||
@web_push_request || WebPushRequest.new(@subscription)
|
||||
end
|
||||
|
||||
Oj.dump(json)
|
||||
def push_notification_json
|
||||
Oj.dump(serialized_notification_in_subscription_locale.as_json)
|
||||
end
|
||||
|
||||
def serialized_notification_in_subscription_locale
|
||||
I18n.with_locale(@subscription.locale.presence || I18n.default_locale) do
|
||||
serialized_notification
|
||||
end
|
||||
end
|
||||
|
||||
def serialized_notification
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
@notification,
|
||||
serializer: Web::NotificationSerializer,
|
||||
scope: @subscription,
|
||||
scope_name: :current_push_subscription
|
||||
)
|
||||
end
|
||||
|
||||
def request_pool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue