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.

54 lines
1.2 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. SendInteractionService.new.(status.stream_entry, account)
  31. end
  32. def remove_reblogs(status)
  33. status.reblogs.each do |reblog|
  34. RemoveStatusService.new.(reblog)
  35. end
  36. end
  37. def unpush(type, receiver, status)
  38. redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id)
  39. FeedManager.instance.broadcast(receiver.id, type: 'delete', id: status.id)
  40. end
  41. def redis
  42. $redis
  43. end
  44. end