Add: フレンドサーバー (#61)
* Fix mastodon version * テーブル作成 * Wip: フレンドサーバーフォローの承認を受信 * Wip: フレンド申請拒否を受信 * Wip: フォローリクエストを受理 * Wip: 相手からのフォロー・アンフォローを受理 * 普通のフォローとフレンドサーバーのフォローを区別するテストを追加 * ドメインブロックによるフォロー拒否 * ドメインブロックしたあと、申請中のフォロリクを取り下げる処理 * スタブに条件を追加 * Wip: 相手からのDelete信号に対応 * DB定義が消えていたので修正 * Wip: ローカル公開投稿をフレンドに送信する処理など * Wip: 未収載+誰でもの投稿をフレンドに送る設定 * Wip: ローカル公開をそのまま送信する設定を考慮 * Fix test * Wip: 他サーバーからのローカル公開投稿の受け入れ * Wip: Web画面作成 * Fix test * Wip: ローカル公開を連合TLに流す * Wip: フレンドサーバーの削除ボタン * Wip: メール通知や設定のテストなど * Wip: 翻訳を作成 * Fix: 却下されたあとフォローボタンが表示されない問題 * Wip: 編集できない問題 * 有効にしていないフレンドサーバーをリストで無効表示
This commit is contained in:
parent
acb29e5b11
commit
87e858a202
66 changed files with 1638 additions and 51 deletions
|
@ -3,6 +3,7 @@
|
|||
class ActivityPub::Activity::Accept < ActivityPub::Activity
|
||||
def perform
|
||||
return accept_follow_for_relay if relay_follow?
|
||||
return accept_follow_for_friend if friend_follow?
|
||||
return accept_follow!(follow_request_from_object) unless follow_request_from_object.nil?
|
||||
|
||||
case @object['type']
|
||||
|
@ -43,6 +44,18 @@ class ActivityPub::Activity::Accept < ActivityPub::Activity
|
|||
relay.present?
|
||||
end
|
||||
|
||||
def accept_follow_for_friend
|
||||
friend.update!(active_state: :accepted)
|
||||
end
|
||||
|
||||
def friend
|
||||
@friend ||= FriendDomain.find_by(domain: @account.domain, active_follow_activity_id: object_uri, active_state: [:pending, :accepted]) if @account.domain.present?
|
||||
end
|
||||
|
||||
def friend_follow?
|
||||
friend.present?
|
||||
end
|
||||
|
||||
def target_uri
|
||||
@target_uri ||= value_or_id(@object['actor'])
|
||||
end
|
||||
|
|
|
@ -447,7 +447,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
|
||||
def related_to_local_activity?
|
||||
fetch? || followed_by_local_accounts? || requested_through_relay? ||
|
||||
responds_to_followed_account? || addresses_local_accounts? || quote_local?
|
||||
responds_to_followed_account? || addresses_local_accounts? || quote_local? || free_friend_domain?
|
||||
end
|
||||
|
||||
def responds_to_followed_account?
|
||||
|
@ -502,6 +502,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
end
|
||||
end
|
||||
|
||||
def free_friend_domain?
|
||||
FriendDomain.free_receivings.exists?(domain: @account.domain)
|
||||
end
|
||||
|
||||
def quote
|
||||
@quote ||= @object['quote'] || @object['quoteUrl'] || @object['quoteURL'] || @object['_misskey_quote']
|
||||
end
|
||||
|
|
|
@ -4,6 +4,8 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
def perform
|
||||
if @account.uri == object_uri
|
||||
delete_person
|
||||
elsif object_uri == ActivityPub::TagManager::COLLECTIONS[:public]
|
||||
delete_friend
|
||||
else
|
||||
delete_note
|
||||
end
|
||||
|
@ -42,6 +44,11 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
end
|
||||
end
|
||||
|
||||
def delete_friend
|
||||
friend = FriendDomain.find_by(domain: @account.domain)
|
||||
friend&.destroy
|
||||
end
|
||||
|
||||
def forwarder
|
||||
@forwarder ||= ActivityPub::Forwarder.new(@account, @json, @status)
|
||||
end
|
||||
|
|
|
@ -4,6 +4,8 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
|||
include Payloadable
|
||||
|
||||
def perform
|
||||
return request_follow_for_friend if friend_follow?
|
||||
|
||||
target_account = account_from_uri(object_uri)
|
||||
|
||||
return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id'])
|
||||
|
@ -43,6 +45,36 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
|||
ActivityPub::DeliveryWorker.perform_async(json, target_account.id, @account.inbox_url)
|
||||
end
|
||||
|
||||
def request_follow_for_friend
|
||||
already_accepted = false
|
||||
|
||||
if friend.present?
|
||||
already_accepted = friend.they_are_accepted?
|
||||
friend.update!(passive_state: :pending, passive_follow_activity_id: @json['id'])
|
||||
else
|
||||
@friend = FriendDomain.create!(domain: @account.domain, passive_state: :pending, passive_follow_activity_id: @json['id'])
|
||||
end
|
||||
|
||||
if already_accepted || friend.unlocked || Setting.unlocked_friend
|
||||
friend.accept!
|
||||
else
|
||||
# Notify for admin even if unlocked
|
||||
notify_staff_about_pending_friend_server!
|
||||
end
|
||||
end
|
||||
|
||||
def friend
|
||||
@friend ||= FriendDomain.find_by(domain: @account.domain) if @account.domain.present?
|
||||
end
|
||||
|
||||
def friend_follow?
|
||||
@json['object'] == ActivityPub::TagManager::COLLECTIONS[:public] && !block_friend?
|
||||
end
|
||||
|
||||
def block_friend?
|
||||
@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
|
||||
|
@ -73,4 +105,12 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
|
|||
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?
|
||||
|
||||
AdminMailer.with(recipient: u.account).new_pending_friend_server(friend).deliver_later
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
class ActivityPub::Activity::Reject < ActivityPub::Activity
|
||||
def perform
|
||||
return reject_follow_for_relay if relay_follow?
|
||||
return reject_follow_for_friend if friend_follow?
|
||||
return follow_request_from_object.reject! unless follow_request_from_object.nil?
|
||||
return UnfollowService.new.call(follow_from_object.account, @account) unless follow_from_object.nil?
|
||||
|
||||
|
@ -37,6 +38,18 @@ class ActivityPub::Activity::Reject < ActivityPub::Activity
|
|||
relay.present?
|
||||
end
|
||||
|
||||
def reject_follow_for_friend
|
||||
friend.update!(active_state: :rejected)
|
||||
end
|
||||
|
||||
def friend
|
||||
@friend ||= FriendDomain.find_by(domain: @account.domain, active_follow_activity_id: object_uri, active_state: [:pending, :accepted]) if @account.domain.present?
|
||||
end
|
||||
|
||||
def friend_follow?
|
||||
friend.present?
|
||||
end
|
||||
|
||||
def target_uri
|
||||
@target_uri ||= value_or_id(@object['actor'])
|
||||
end
|
||||
|
|
|
@ -87,6 +87,8 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity
|
|||
end
|
||||
|
||||
def undo_follow
|
||||
return remove_follow_from_friend if friend_follow?
|
||||
|
||||
target_account = account_from_uri(target_uri)
|
||||
|
||||
return if target_account.nil? || !target_account.local?
|
||||
|
@ -100,6 +102,18 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity
|
|||
end
|
||||
end
|
||||
|
||||
def remove_follow_from_friend
|
||||
friend.update!(passive_state: :idle, passive_follow_activity_id: nil)
|
||||
end
|
||||
|
||||
def friend
|
||||
@friend ||= FriendDomain.find_by(domain: @account.domain) if @account.domain.present? && @object['object'] == ActivityPub::TagManager::COLLECTIONS[:public]
|
||||
end
|
||||
|
||||
def friend_follow?
|
||||
friend.present?
|
||||
end
|
||||
|
||||
def undo_like_original
|
||||
status = status_from_uri(target_uri)
|
||||
|
||||
|
|
|
@ -76,6 +76,8 @@ class ActivityPub::Parser::StatusParser
|
|||
def visibility
|
||||
if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) }
|
||||
:public
|
||||
elsif audience_to.include?('LocalPublic')
|
||||
:public_unlisted
|
||||
elsif audience_cc.any? { |cc| ActivityPub::TagManager.instance.public_collection?(cc) }
|
||||
:unlisted
|
||||
elsif audience_to.include?('as:LoginOnly') || audience_to.include?('LoginUser')
|
||||
|
@ -198,6 +200,8 @@ class ActivityPub::Parser::StatusParser
|
|||
:public
|
||||
elsif audience_searchable_by.include?('as:Limited')
|
||||
:limited
|
||||
elsif audience_searchable_by.include?('LocalPublic')
|
||||
:public_unlisted
|
||||
elsif audience_searchable_by.include?(@account.followers_url)
|
||||
:private
|
||||
else
|
||||
|
|
|
@ -126,6 +126,12 @@ class ActivityPub::TagManager
|
|||
end
|
||||
end
|
||||
|
||||
def to_for_friend(status)
|
||||
to = to(status)
|
||||
to << 'LocalPublic' if status.public_unlisted_visibility?
|
||||
to
|
||||
end
|
||||
|
||||
# Secondary audience of a status
|
||||
# Public statuses go out to followers as well
|
||||
# Unlisted statuses go to the public as well
|
||||
|
@ -147,7 +153,7 @@ class ActivityPub::TagManager
|
|||
end
|
||||
|
||||
def cc_for_misskey(status)
|
||||
if (status.account.user&.setting_reject_unlisted_subscription && status.visibility == 'unlisted') || (status.account.user&.setting_reject_public_unlisted_subscription && status.visibility == 'public_unlisted')
|
||||
if (status.account.user&.setting_reject_unlisted_subscription && status.unlisted_visibility?) || (status.account.user&.setting_reject_public_unlisted_subscription && status.public_unlisted_visibility?)
|
||||
cc = cc_private_visibility(status)
|
||||
cc << uri_for(status.reblog.account) if status.reblog?
|
||||
return cc
|
||||
|
@ -251,6 +257,12 @@ class ActivityPub::TagManager
|
|||
searchable_by.concat(mentions_uris(status)).compact
|
||||
end
|
||||
|
||||
def searchable_by_for_friend(status)
|
||||
searchable = searchable_by(status)
|
||||
searchable << 'LocalPublic' if status.compute_searchability_local == 'public_unlisted'
|
||||
searchable
|
||||
end
|
||||
|
||||
def account_searchable_by(account)
|
||||
case account.compute_searchability_activitypub
|
||||
when 'public'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue