fedibird-fe/app/services/unsubscribe_account_service.rb
2022-05-11 00:48:01 +09:00

23 lines
833 B
Ruby

# frozen_string_literal: true
class UnsubscribeAccountService < BaseService
# UnsubscribeAccount
# @param [Account] source_account Where to unsubscribe from
# @param [Account] target_account Which to unsubscribe
def call(source_account, target_account, list_id = nil)
if (list_id == :all)
AccountSubscribe.where(account: source_account, target_account: target_account).each do |subscribe|
subscribe.destroy!
UnmergeWorker.perform_async(target_account.id, source_account.id) if subscribe.list_id.nil?
end
end
subscribe = AccountSubscribe.find_by(account: source_account, target_account: target_account, list_id: list_id)
return unless subscribe
subscribe.destroy!
UnmergeWorker.perform_async(target_account.id, source_account.id) if list_id.nil?
subscribe
end
end