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.

55 lines
1.3 KiB

  1. class RemoveStatusService < BaseService
  2. def call(status)
  3. remove_from_self(status) if status.account.local?
  4. remove_from_followers(status)
  5. remove_from_mentioned(status)
  6. remove_reblogs(status)
  7. status.destroy!
  8. end
  9. private
  10. def remove_from_self(status)
  11. unpush(:home, status.account, status)
  12. end
  13. def remove_from_followers(status)
  14. status.account.followers.each do |follower|
  15. next unless follower.local?
  16. unpush(:home, follower, status)
  17. end
  18. end
  19. def remove_from_mentioned(status)
  20. status.mentions.each do |mention|
  21. mentioned_account = mention.account
  22. if mentioned_account.local?
  23. unpush(:mentions, mentioned_account, status)
  24. else
  25. send_delete_salmon(mentioned_account, status)
  26. end
  27. end
  28. end
  29. def send_delete_salmon(account, status)
  30. return unless status.local?
  31. NotificationWorker.perform_async(status.stream_entry.id, account.id)
  32. end
  33. def remove_reblogs(status)
  34. status.reblogs.each do |reblog|
  35. RemoveStatusService.new.call(reblog)
  36. end
  37. end
  38. def unpush(type, receiver, status)
  39. redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id)
  40. FeedManager.instance.broadcast(receiver.id, type: 'delete', id: status.id)
  41. end
  42. def redis
  43. $redis
  44. end
  45. end