闭社主体 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.

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