From 7b9a4af3112dc4edcd378dc94190e2eb8e041f56 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 3 Oct 2016 18:17:06 +0200 Subject: API for blocking and unblocking --- app/services/block_service.rb | 25 +++++++++++++++++++++++++ app/services/unblock_service.rb | 5 +++++ app/services/unfollow_service.rb | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/services/block_service.rb create mode 100644 app/services/unblock_service.rb (limited to 'app/services') diff --git a/app/services/block_service.rb b/app/services/block_service.rb new file mode 100644 index 000000000..6c841d25b --- /dev/null +++ b/app/services/block_service.rb @@ -0,0 +1,25 @@ +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 + $redis + end +end diff --git a/app/services/unblock_service.rb b/app/services/unblock_service.rb new file mode 100644 index 000000000..d24161423 --- /dev/null +++ b/app/services/unblock_service.rb @@ -0,0 +1,5 @@ +class UnblockService < BaseService + def call(account, target_account) + account.unblock!(target_account) if account.blocking?(target_account) + end +end diff --git a/app/services/unfollow_service.rb b/app/services/unfollow_service.rb index feaf28ceb..d22451a74 100644 --- a/app/services/unfollow_service.rb +++ b/app/services/unfollow_service.rb @@ -13,7 +13,7 @@ class UnfollowService < BaseService def unmerge_from_timeline(from_account, into_account) timeline_key = FeedManager.instance.key(:home, into_account.id) - from_account.statuses.find_each do |status| + from_account.statuses.select('id').find_each do |status| redis.zrem(timeline_key, status.id) end -- cgit