forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: #591 リモート保留中アカウントからメンションが来た場合にuriを記録し、承認時にフェッチしに行く処理
- Loading branch information
Showing
14 changed files
with
156 additions
and
14 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
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: pending_statuses | ||
# | ||
# id :bigint(8) not null, primary key | ||
# account_id :bigint(8) not null | ||
# fetch_account_id :bigint(8) not null | ||
# uri :string not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
|
||
class PendingStatus < ApplicationRecord | ||
belongs_to :account | ||
belongs_to :fetch_account, class_name: 'Account' | ||
end |
2 changes: 1 addition & 1 deletion
2
...ervices/enable_follow_requests_service.rb → ...vices/activate_follow_requests_service.rb
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
class ActivateRemoteStatusesService < BaseService | ||
include Payloadable | ||
include FollowHelper | ||
|
||
def call(account) | ||
@account = account | ||
|
||
PendingStatus.transaction do | ||
PendingStatus.where(account: account).find_each do |status_info| | ||
approve_status!(status_info) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def approve_status!(pending) | ||
account_id = pending.account_id | ||
fetch_account_id = pending.fetch_account_id | ||
uri = pending.uri | ||
pending.destroy! | ||
|
||
return if ActivityPub::TagManager.instance.uri_to_resource(uri, Status).present? | ||
|
||
FetchRemoteStatusWorker.perform_async(uri, account_id, fetch_account_id) | ||
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
5 changes: 3 additions & 2 deletions
5
app/workers/enable_follow_requests_worker.rb → ...workers/activate_remote_account_worker.rb
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,13 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class EnableFollowRequestsWorker | ||
class ActivateRemoteAccountWorker | ||
include Sidekiq::Worker | ||
|
||
def perform(account_id) | ||
account = Account.find_by(id: account_id) | ||
return true if account.nil? | ||
return true if account.suspended? | ||
|
||
EnableFollowRequestsService.new.call(account) | ||
ActivateFollowRequestsService.new.call(account) | ||
ActivateRemoteStatusesService.new.call(account) | ||
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class ActivityPub::FetchRemoteStatusWorker | ||
include Sidekiq::Worker | ||
include Redisable | ||
|
||
sidekiq_options queue: 'pull', retry: 3 | ||
|
||
def perform(uri, author_account_id, on_behalf_of_account_id) | ||
author = Account.find(author_account_id) | ||
on_behalf_of = on_behalf_of_account_id.present? ? Account.find(on_behalf_of_account_id) : nil | ||
|
||
ActivityPub::FetchRemoteStatusService.new.call(uri, on_behalf_of: on_behalf_of, expected_actor_uri: author, request_id: uri) | ||
rescue ActiveRecord::RecordNotFound, Mastodon::RaceConditionError | ||
true | ||
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreatePendingStatuses < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :pending_statuses do |t| | ||
t.references :account, null: false, foreign_key: { on_delete: :cascade } | ||
t.references :fetch_account, null: false, foreign_key: { to_table: 'accounts', on_delete: :cascade } | ||
t.string :uri, null: false, index: { unique: true } | ||
|
||
t.timestamps | ||
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