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

26 lines
817 B

  1. class UnfollowService < BaseService
  2. # Unfollow and notify the remote user
  3. # @param [Account] source_account Where to unfollow from
  4. # @param [Account] target_account Which to unfollow
  5. def call(source_account, target_account)
  6. follow = source_account.unfollow!(target_account)
  7. NotificationWorker.perform_async(follow.stream_entry.id, target_account.id) unless target_account.local?
  8. unmerge_from_timeline(target_account, source_account)
  9. end
  10. private
  11. def unmerge_from_timeline(from_account, into_account)
  12. timeline_key = FeedManager.instance.key(:home, into_account.id)
  13. from_account.statuses.select('id').find_each do |status|
  14. redis.zrem(timeline_key, status.id)
  15. end
  16. FeedManager.instance.broadcast(into_account.id, type: 'unmerge')
  17. end
  18. def redis
  19. $redis
  20. end
  21. end