* Add: #586 保留中のリモートアカウントからのフォローが飛んできた場合に記録する * 本家に戻す処理を修正 * Fix test * Fix worker link * Fix test * リモートアカウント拒否時に既存のリクエストを削除
This commit is contained in:
parent
1b3c0e3fb7
commit
dfc9f35d71
15 changed files with 262 additions and 31 deletions
35
app/helpers/follow_helper.rb
Normal file
35
app/helpers/follow_helper.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module FollowHelper
|
||||
def request_pending_follow?(source_account, target_account)
|
||||
target_account.locked? || source_account.silenced? || block_straight_follow?(source_account) ||
|
||||
((source_account.bot? || proxy_account?(source_account)) && target_account.user&.setting_lock_follow_from_bot)
|
||||
end
|
||||
|
||||
def block_straight_follow?(account)
|
||||
return false if account.local?
|
||||
|
||||
DomainBlock.reject_straight_follow?(account.domain)
|
||||
end
|
||||
|
||||
def proxy_account?(account)
|
||||
(account.username.downcase.include?('_proxy') ||
|
||||
account.username.downcase.end_with?('proxy') ||
|
||||
account.username.downcase.include?('_bot_') ||
|
||||
account.username.downcase.end_with?('bot') ||
|
||||
account.display_name&.downcase&.include?('proxy') ||
|
||||
account.display_name&.include?('プロキシ') ||
|
||||
account.note&.include?('プロキシ')) &&
|
||||
(account.following_count.zero? || account.following_count > account.followers_count) &&
|
||||
proxyable_software?(account)
|
||||
end
|
||||
|
||||
def proxyable_software?(account)
|
||||
return false if account.local?
|
||||
|
||||
info = InstanceInfo.find_by(domain: account.domain)
|
||||
return false if info.nil?
|
||||
|
||||
%w(misskey calckey firefish meisskey cherrypick sharkey).include?(info.software)
|
||||
end
|
||||
end
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class ActivityPub::Activity::Follow < ActivityPub::Activity
|
||||
include Payloadable
|
||||
include FollowHelper
|
||||
|
||||
def perform
|
||||
return request_follow_for_friend if friend_follow?
|
||||
|
@ -11,7 +12,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
|||
return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id'])
|
||||
|
||||
# Update id of already-existing follow requests
|
||||
existing_follow_request = ::FollowRequest.find_by(account: @account, target_account: target_account)
|
||||
existing_follow_request = ::FollowRequest.find_by(account: @account, target_account: target_account) || PendingFollowRequest.find_by(account: @account, target_account: target_account)
|
||||
unless existing_follow_request.nil?
|
||||
existing_follow_request.update!(uri: @json['id'])
|
||||
return
|
||||
|
@ -30,9 +31,16 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
|||
return
|
||||
end
|
||||
|
||||
if @account.suspended? && @account.remote_pending?
|
||||
PendingFollowRequest.create!(account: @account, target_account: target_account, uri: @json['id'])
|
||||
return
|
||||
elsif @account.suspended?
|
||||
return
|
||||
end
|
||||
|
||||
follow_request = FollowRequest.create!(account: @account, target_account: target_account, uri: @json['id'])
|
||||
|
||||
if target_account.locked? || @account.silenced? || block_straight_follow? || ((@account.bot? || proxy_account?) && target_account.user&.setting_lock_follow_from_bot)
|
||||
if request_pending_follow?(@account, target_account)
|
||||
LocalNotificationWorker.perform_async(target_account.id, follow_request.id, 'FollowRequest', 'follow_request')
|
||||
else
|
||||
AuthorizeFollowService.new.call(@account, target_account)
|
||||
|
@ -79,37 +87,10 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
|||
@block_friend ||= DomainBlock.reject_friend?(@account.domain) || DomainBlock.blocked?(@account.domain)
|
||||
end
|
||||
|
||||
def block_straight_follow?
|
||||
@block_straight_follow ||= DomainBlock.reject_straight_follow?(@account.domain)
|
||||
end
|
||||
|
||||
def block_new_follow?
|
||||
@block_new_follow ||= DomainBlock.reject_new_follow?(@account.domain)
|
||||
end
|
||||
|
||||
def proxy_account?
|
||||
(@account.username.downcase.include?('_proxy') ||
|
||||
@account.username.downcase.end_with?('proxy') ||
|
||||
@account.username.downcase.include?('_bot_') ||
|
||||
@account.username.downcase.end_with?('bot') ||
|
||||
@account.display_name&.downcase&.include?('proxy') ||
|
||||
@account.display_name&.include?('プロキシ') ||
|
||||
@account.note&.include?('プロキシ')) &&
|
||||
(@account.following_count.zero? || @account.following_count > @account.followers_count) &&
|
||||
proxyable_software?
|
||||
end
|
||||
|
||||
def proxyable_software?
|
||||
info = instance_info
|
||||
return false if info.nil?
|
||||
|
||||
%w(misskey calckey firefish meisskey cherrypick sharkey).include?(info.software)
|
||||
end
|
||||
|
||||
def instance_info
|
||||
@instance_info ||= InstanceInfo.find_by(domain: @account.domain)
|
||||
end
|
||||
|
||||
def notify_staff_about_pending_friend_server!
|
||||
User.those_who_can(:manage_federation).includes(:account).find_each do |u|
|
||||
next unless u.allows_pending_friend_server_emails?
|
||||
|
|
|
@ -300,10 +300,13 @@ class Account < ApplicationRecord
|
|||
def approve_remote!
|
||||
update!(remote_pending: false)
|
||||
unsuspend!
|
||||
EnableFollowRequestsWorker.perform_async(id)
|
||||
end
|
||||
|
||||
def reject_remote!
|
||||
update!(remote_pending: false, suspension_origin: :local)
|
||||
pending_follow_requests.destroy_all
|
||||
suspend!
|
||||
end
|
||||
|
||||
def sensitized?
|
||||
|
|
|
@ -74,6 +74,7 @@ module Account::Interactions
|
|||
included do
|
||||
# Follow relations
|
||||
has_many :follow_requests, dependent: :destroy
|
||||
has_many :pending_follow_requests, dependent: :destroy
|
||||
|
||||
with_options class_name: 'Follow', dependent: :destroy do
|
||||
has_many :active_relationships, foreign_key: 'account_id', inverse_of: :account
|
||||
|
|
19
app/models/pending_follow_request.rb
Normal file
19
app/models/pending_follow_request.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: pending_follow_requests
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8) not null
|
||||
# target_account_id :bigint(8) not null
|
||||
# uri :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class PendingFollowRequest < ApplicationRecord
|
||||
belongs_to :account
|
||||
belongs_to :target_account, class_name: 'Account'
|
||||
|
||||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
end
|
|
@ -48,13 +48,17 @@ class ActivityPub::ProcessCollectionService < BaseService
|
|||
end
|
||||
|
||||
def suspended_actor?
|
||||
@account.suspended? && !activity_allowed_while_suspended?
|
||||
@account.suspended? && (@account.remote_pending ? !activity_allowed_while_remote_pending? : !activity_allowed_while_suspended?)
|
||||
end
|
||||
|
||||
def activity_allowed_while_suspended?
|
||||
%w(Delete Reject Undo Update).include?(@json['type'])
|
||||
end
|
||||
|
||||
def activity_allowed_while_remote_pending?
|
||||
%w(Follow).include?(@json['type']) || activity_allowed_while_suspended?
|
||||
end
|
||||
|
||||
def process_items(items)
|
||||
items.reverse_each.filter_map { |item| process_item(item) }
|
||||
end
|
||||
|
|
|
@ -28,6 +28,7 @@ class DeleteAccountService < BaseService
|
|||
notifications
|
||||
owned_lists
|
||||
passive_relationships
|
||||
pending_follow_requests
|
||||
report_notes
|
||||
scheduled_statuses
|
||||
scheduled_expiration_statuses
|
||||
|
@ -57,6 +58,7 @@ class DeleteAccountService < BaseService
|
|||
muted_by_relationships
|
||||
notifications
|
||||
owned_lists
|
||||
pending_follow_requests
|
||||
scheduled_statuses
|
||||
scheduled_expiration_statuses
|
||||
status_pins
|
||||
|
|
32
app/services/enable_follow_requests_service.rb
Normal file
32
app/services/enable_follow_requests_service.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EnableFollowRequestsService < BaseService
|
||||
include Payloadable
|
||||
include FollowHelper
|
||||
|
||||
def call(account)
|
||||
@account = account
|
||||
|
||||
PendingFollowRequest.transaction do
|
||||
PendingFollowRequest.where(account: account).find_each do |follow_request|
|
||||
approve_follow!(follow_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def approve_follow!(pending)
|
||||
follow_request = FollowRequest.create!(account: @account, target_account: pending.target_account, uri: pending.uri)
|
||||
pending.destroy!
|
||||
|
||||
target_account = follow_request.target_account
|
||||
|
||||
if request_pending_follow?(@account, target_account)
|
||||
LocalNotificationWorker.perform_async(target_account.id, follow_request.id, 'FollowRequest', 'follow_request')
|
||||
else
|
||||
AuthorizeFollowService.new.call(@account, target_account)
|
||||
LocalNotificationWorker.perform_async(target_account.id, ::Follow.find_by(account: @account, target_account: target_account).id, 'Follow', 'follow')
|
||||
end
|
||||
end
|
||||
end
|
13
app/workers/enable_follow_requests_worker.rb
Normal file
13
app/workers/enable_follow_requests_worker.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EnableFollowRequestsWorker
|
||||
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)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue