This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2016-11-15 16:56:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-03 18:17:06 +02:00
|
|
|
class BlockService < BaseService
|
|
|
|
def call(account, target_account)
|
|
|
|
return if account.id == target_account.id
|
|
|
|
|
|
|
|
UnfollowService.new.call(account, target_account) if account.following?(target_account)
|
|
|
|
account.block!(target_account)
|
|
|
|
clear_mentions(account, target_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def clear_mentions(account, target_account)
|
|
|
|
timeline_key = FeedManager.instance.key(:mentions, account.id)
|
|
|
|
|
|
|
|
target_account.statuses.select('id').find_each do |status|
|
|
|
|
redis.zrem(timeline_key, status.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
FeedManager.instance.broadcast(account.id, type: 'block', id: target_account.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def redis
|
2016-11-15 16:56:29 +01:00
|
|
|
Redis.current
|
2016-10-03 18:17:06 +02:00
|
|
|
end
|
|
|
|
end
|