Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from https://github.com/mastodon/mastodon, unmodified.
78 lines
2.2 KiB
Ruby
78 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class UnfollowService < BaseService
|
|
include Payloadable
|
|
include Redisable
|
|
include Lockable
|
|
|
|
# Unfollow and notify the remote user
|
|
# @param [Account] follower Where to unfollow from
|
|
# @param [Account] followee Which to unfollow
|
|
# @param [Hash] options
|
|
# @option [Boolean] :skip_unmerge
|
|
def call(follower, followee, options = {})
|
|
@follower = follower
|
|
@followee = followee
|
|
@options = options
|
|
|
|
with_redis_lock("relationship:#{[follower.id, followee.id].sort.join(':')}") do
|
|
unfollow! || undo_follow_request!
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def unfollow!
|
|
follow = Follow.find_by(account: @follower, target_account: @followee)
|
|
return unless follow
|
|
|
|
# List members are removed immediately with the follow relationship removal,
|
|
# so we need to fetch the list IDs first
|
|
list_ids = @follower.owned_lists.with_list_account(@followee).pluck(:list_id) unless @options[:skip_unmerge]
|
|
|
|
follow.destroy!
|
|
|
|
if @followee.local? && @follower.remote? && @follower.activitypub?
|
|
send_reject_follow(follow)
|
|
elsif @followee.remote? && @followee.activitypub?
|
|
send_undo_follow(follow)
|
|
end
|
|
|
|
unless @options[:skip_unmerge]
|
|
UnmergeWorker.perform_async(@followee.id, @follower.id, 'home')
|
|
UnmergeWorker.push_bulk(list_ids) do |list_id|
|
|
[@followee.id, list_id, 'list']
|
|
end
|
|
end
|
|
|
|
follow
|
|
end
|
|
|
|
def undo_follow_request!
|
|
follow_request = FollowRequest.find_by(account: @follower, target_account: @followee)
|
|
return unless follow_request
|
|
|
|
follow_request.destroy!
|
|
|
|
send_undo_follow(follow_request) unless @followee.local?
|
|
|
|
follow_request
|
|
end
|
|
|
|
def send_undo_follow(follow)
|
|
ActivityPub::DeliveryWorker.perform_async(build_json(follow), follow.account_id, follow.target_account.inbox_url)
|
|
end
|
|
|
|
def send_reject_follow(follow)
|
|
ActivityPub::DeliveryWorker.perform_async(build_reject_json(follow), follow.target_account_id, follow.account.inbox_url)
|
|
end
|
|
|
|
def build_json(follow)
|
|
serialize_payload(follow, ActivityPub::UndoFollowSerializer).to_json
|
|
end
|
|
|
|
def build_reject_json(follow)
|
|
serialize_payload(follow, ActivityPub::RejectFollowSerializer).to_json
|
|
end
|
|
end
|