Skip to content

Commit

Permalink
Fix to remove AccountSubscribe on block
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo authored and umonaca committed Oct 29, 2020
1 parent a398fb1 commit 678bbee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/lib/activitypub/activity/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def perform
end

UnfollowService.new.call(target_account, @account) if target_account.following?(@account)
UnsubscribeAccountService.new.call(target_account, @account, :all)

@account.block!(target_account, uri: @json['id']) unless delete_arrived_first?(@json['id'])
end
Expand Down
3 changes: 2 additions & 1 deletion app/lib/feed_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def filter_from_home?(status, receiver_id, crutches)
end

return true if check_for_blocks.any? { |target_account_id| crutches[:blocking][target_account_id] || crutches[:muting][target_account_id] }
return true if crutches[:blocked_by][status.account_id]

if status.reblog? # Filter out a reblog
should_filter = crutches[:hiding_reblogs][status.account_id] # if the reblogger's reblogs are suppressed
Expand Down Expand Up @@ -520,7 +521,7 @@ def build_crutches(receiver_id, statuses)
crutches[:muting] = Mute.where(account_id: receiver_id, target_account_id: check_for_blocks).pluck(:target_account_id).each_with_object({}) { |id, mapping| mapping[id] = true }
crutches[:domain_blocking] = AccountDomainBlock.where(account_id: receiver_id, domain: statuses.map { |s| s.account&.domain }.compact).pluck(:domain).each_with_object({}) { |domain, mapping| mapping[domain] = true }
crutches[:domain_blocking_r] = AccountDomainBlock.where(account_id: receiver_id, domain: statuses.map { |s| s.reblog&.account&.domain }.compact).pluck(:domain).each_with_object({}) { |domain, mapping| mapping[domain] = true }
crutches[:blocked_by] = Block.where(target_account_id: receiver_id, account_id: statuses.map { |s| s.reblog&.account_id }.compact).pluck(:account_id).each_with_object({}) { |id, mapping| mapping[id] = true }
crutches[:blocked_by] = Block.where(target_account_id: receiver_id, account_id: statuses.flat_map { |s| [s&.account_id, s.reblog&.account_id] }.compact).pluck(:account_id).each_with_object({}) { |id, mapping| mapping[id] = true }
crutches[:following_tag_by] = FollowTag.where(account_id: receiver_id, tag: statuses.map { |s| s.tags }.flatten.uniq.compact).pluck(:tag_id).each_with_object({}) { |tag_id, mapping| mapping[tag_id] = true }
crutches[:domain_subscribe] = DomainSubscribe.where(account_id: receiver_id, list_id: nil, domain: statuses.map { |s| s&.account&.domain }.compact).pluck(:domain).each_with_object({}) { |domain, mapping| mapping[domain] = true }
crutches[:account_subscribe] = AccountSubscribe.where(account_id: receiver_id, target_account_id: statuses.map(&:account_id).compact).pluck(:target_account_id).each_with_object({}) { |id, mapping| mapping[id] = true }
Expand Down
2 changes: 2 additions & 0 deletions app/services/block_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def call(account, target_account)
UnfollowService.new.call(account, target_account) if account.following?(target_account)
UnfollowService.new.call(target_account, account) if target_account.following?(account)
RejectFollowService.new.call(target_account, account) if target_account.requested?(account)
UnsubscribeAccountService.new.call(account, target_account, :all)
UnsubscribeAccountService.new.call(target_account, account, :all)

block = account.block!(target_account)

Expand Down
7 changes: 7 additions & 0 deletions app/services/unsubscribe_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class UnsubscribeAccountService < BaseService
# @param [Account] source_account Where to unsubscribe from
# @param [Account] target_account Which to unsubscribe
def call(source_account, target_account, list_id = nil)
if (list_id == :all)
AccountSubscribe.where(account: source_account, target_account: target_account).each do |subscribe|
subscribe.destroy!
UnmergeWorker.perform_async(target_account.id, source_account.id) if subscribe.list_id.nil?
end
end

subscribe = AccountSubscribe.find_by(account: source_account, target_account: target_account, list_id: list_id)

return unless subscribe
Expand Down

0 comments on commit 678bbee

Please sign in to comment.