fedibird-fe/app/services/unsubscribe_account_service.rb

24 lines
833 B
Ruby
Raw Normal View History

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-03-21 04:25:30 +00:00
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
2020-03-21 04:25:30 +00:00
subscribe = AccountSubscribe.find_by(account: source_account, target_account: target_account, list_id: list_id)
2019-08-30 08:02:41 +00:00
return unless subscribe
subscribe.destroy!
2020-03-21 04:25:30 +00:00
UnmergeWorker.perform_async(target_account.id, source_account.id) if list_id.nil?
2019-08-30 08:02:41 +00:00
subscribe
end
end