2019-08-30 08:02:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UnsubscribeAccountService < BaseService
|
|
|
|
# UnsubscribeAccount
|
|
|
|
# @param [Account] source_account Where to unsubscribe from
|
|
|
|
# @param [Account] target_account Which to unsubscribe
|
2020-11-15 06:57:58 +00:00
|
|
|
def call(source_account, target_account, options = {})
|
|
|
|
if (options[:list_id] == :all)
|
|
|
|
subscribes = AccountSubscribe.where(account: source_account, target_account: target_account)
|
|
|
|
else
|
|
|
|
subscribes = AccountSubscribe.where(account: source_account, target_account: target_account, list_id: options[:list_id])
|
2020-06-18 03:10:50 +00:00
|
|
|
end
|
|
|
|
|
2020-11-15 06:57:58 +00:00
|
|
|
subscribes.each do |subscribe|
|
|
|
|
list_id = subscribe.list_id
|
|
|
|
subscribe.destroy!
|
|
|
|
if list_id.nil? && !source_account.delivery_following?(target_account)
|
|
|
|
UnmergeWorker.perform_async(target_account.id, source_account.id)
|
|
|
|
elsif !ListAccount.where(list_id: list_id, account_id: target_account.id).exists?
|
|
|
|
UnmergeWorker.perform_async(target_account.id, source_account.id, list_id: list_id)
|
|
|
|
end
|
|
|
|
end
|
2019-08-30 08:02:41 +00:00
|
|
|
end
|
|
|
|
end
|