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.
Merge remote-tracking branch 'origin/kb_development' into kbtopic-add…
…-block-non-follower
- Loading branch information
Showing
21 changed files
with
282 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
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,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 |
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,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 |
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,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 |
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
17 changes: 17 additions & 0 deletions
17
db/migrate/20240217230006_create_pending_follow_requests.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreatePendingFollowRequests < ActiveRecord::Migration[7.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
create_table :pending_follow_requests do |t| | ||
t.references :account, null: false, foreign_key: { on_delete: :cascade }, index: false | ||
t.references :target_account, null: false, foreign_key: { to_table: 'accounts', on_delete: :cascade } | ||
t.string :uri, null: false, index: { unique: true } | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :pending_follow_requests, [:account_id, :target_account_id], unique: 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
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
Fabricator(:pending_follow_request) do | ||
account { Fabricate.build(:account) } | ||
target_account { Fabricate.build(:account, locked: true) } | ||
uri 'https://example.com/follow' | ||
end |
Oops, something went wrong.