闭社主体 forked from https://github.com/tootsuite/mastodon
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.

74 lines
1.8 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. if status.account.local?
  12. HubPingWorker.perform_async(status.account.id)
  13. Pubsubhubbub::DistributionWorker.perform_async(status.stream_entry.id)
  14. end
  15. end
  16. private
  17. def remove_from_self(status)
  18. unpush(:home, status.account, status)
  19. end
  20. def remove_from_followers(status)
  21. status.account.followers.each do |follower|
  22. next unless follower.local?
  23. unpush(:home, follower, status)
  24. end
  25. end
  26. def remove_from_mentioned(status)
  27. status.mentions.each do |mention|
  28. mentioned_account = mention.account
  29. if mentioned_account.local?
  30. unpush(:mentions, mentioned_account, status)
  31. else
  32. send_delete_salmon(mentioned_account, status)
  33. end
  34. end
  35. end
  36. def send_delete_salmon(account, status)
  37. return unless status.local?
  38. NotificationWorker.perform_async(status.stream_entry.id, account.id)
  39. end
  40. def remove_reblogs(status)
  41. status.reblogs.each do |reblog|
  42. RemoveStatusService.new.call(reblog)
  43. end
  44. end
  45. def unpush(type, receiver, status)
  46. redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id)
  47. FeedManager.instance.broadcast(receiver.id, type: 'delete', id: status.id)
  48. end
  49. def remove_from_hashtags(status)
  50. status.tags.each do |tag|
  51. FeedManager.instance.broadcast("hashtag:#{tag.name}", type: 'delete', id: status.id)
  52. end
  53. end
  54. def remove_from_public(status)
  55. FeedManager.instance.broadcast(:public, type: 'delete', id: status.id)
  56. end
  57. def redis
  58. Redis.current
  59. end
  60. end