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.

27 lines
850 B

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