parent
2c9e672ee2
commit
7b9a4af311
@ -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 |
@ -0,0 +1,5 @@ |
|||||||
|
class UnblockService < BaseService |
||||||
|
def call(account, target_account) |
||||||
|
account.unblock!(target_account) if account.blocking?(target_account) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
require 'rails_helper' |
||||||
|
|
||||||
|
RSpec.describe BlockService do |
||||||
|
subject { BlockService.new } |
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
require 'rails_helper' |
||||||
|
|
||||||
|
RSpec.describe UnblockService do |
||||||
|
subject { UnblockService.new } |
||||||
|
end |
Loading…
Reference in new issue