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.

69 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. class RemoveStatusService < BaseService
  3. def call(status)
  4. remove_from_self(status) if status.account.local?
  5. remove_from_followers(status)
  6. remove_from_mentioned(status)
  7. remove_reblogs(status)
  8. remove_from_hashtags(status)
  9. remove_from_public(status)
  10. status.destroy!
  11. end
  12. private
  13. def remove_from_self(status)
  14. unpush(:home, status.account, status)
  15. end
  16. def remove_from_followers(status)
  17. status.account.followers.each do |follower|
  18. next unless follower.local?
  19. unpush(:home, follower, status)
  20. end
  21. end
  22. def remove_from_mentioned(status)
  23. status.mentions.each do |mention|
  24. mentioned_account = mention.account
  25. if mentioned_account.local?
  26. unpush(:mentions, mentioned_account, status)
  27. else
  28. send_delete_salmon(mentioned_account, status)
  29. end
  30. end
  31. end
  32. def send_delete_salmon(account, status)
  33. return unless status.local?
  34. NotificationWorker.perform_async(status.stream_entry.id, account.id)
  35. end
  36. def remove_reblogs(status)
  37. status.reblogs.each do |reblog|
  38. RemoveStatusService.new.call(reblog)
  39. end
  40. end
  41. def unpush(type, receiver, status)
  42. redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id)
  43. FeedManager.instance.broadcast(receiver.id, type: 'delete', id: status.id)
  44. end
  45. def remove_from_hashtags(status)
  46. status.tags.each do |tag|
  47. FeedManager.instance.broadcast("hashtag:#{tag.name}", type: 'delete', id: status.id)
  48. end
  49. end
  50. def remove_from_public(status)
  51. FeedManager.instance.broadcast(:public, type: 'delete', id: status.id)
  52. end
  53. def redis
  54. Redis.current
  55. end
  56. end