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.

31 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class AfterBlockService < BaseService
  3. def call(account, target_account)
  4. clear_timelines(account, target_account)
  5. clear_notifications(account, target_account)
  6. end
  7. private
  8. def clear_timelines(account, target_account)
  9. home_key = FeedManager.instance.key(:home, account.id)
  10. redis.pipelined do
  11. target_account.statuses.select('id').reorder(nil).find_each do |status|
  12. redis.zrem(home_key, status.id)
  13. end
  14. end
  15. end
  16. def clear_notifications(account, target_account)
  17. Notification.where(account: account).joins(:follow).where(activity_type: 'Follow', follows: { account_id: target_account.id }).delete_all
  18. Notification.where(account: account).joins(mention: :status).where(activity_type: 'Mention', statuses: { account_id: target_account.id }).delete_all
  19. Notification.where(account: account).joins(:favourite).where(activity_type: 'Favourite', favourites: { account_id: target_account.id }).delete_all
  20. Notification.where(account: account).joins(:status).where(activity_type: 'Status', statuses: { account_id: target_account.id }).delete_all
  21. end
  22. def redis
  23. Redis.current
  24. end
  25. end