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.

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