You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
696 B

  1. # frozen_string_literal: true
  2. class BlockService < BaseService
  3. def call(account, target_account)
  4. return if account.id == target_account.id
  5. UnfollowService.new.call(account, target_account) if account.following?(target_account)
  6. account.block!(target_account)
  7. clear_mentions(account, target_account)
  8. end
  9. private
  10. def clear_mentions(account, target_account)
  11. timeline_key = FeedManager.instance.key(:mentions, account.id)
  12. target_account.statuses.select('id').find_each do |status|
  13. redis.zrem(timeline_key, status.id)
  14. end
  15. FeedManager.instance.broadcast(account.id, type: 'block', id: target_account.id)
  16. end
  17. def redis
  18. Redis.current
  19. end
  20. end