blob: 4253f6502dce2f854329aae30d231f15e12ace3e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# frozen_string_literal: true
class StatusFilter
attr_reader :status, :account
def initialize(status, account, preloaded_relations = {})
@status = status
@account = account
@preloaded_relations = preloaded_relations
end
def filtered?
return false if !account.nil? && account.id == status.account_id
blocked_by_policy? || (account_present? && filtered_status?) || silenced_account?
end
private
def account_present?
!account.nil?
end
def filtered_status?
blocking_account? || blocking_domain? || muting_account? || filtered_reference?
end
def filtered_reference?
filtered_reply = reply_to_blocked? || reply_to_muted?
# I don't think this should happen, but just in case...
return filtered_reply if status&.mentions.nil?
# filter non-op posts replying to something marked no replies
return true if reply_to_no_replies?
# Grab a list of account IDs mentioned in the status.
mentioned_account_ids = status.mentions.pluck(:account_id)
# Don't filter statuses mentioning you.
return false if mentioned_account_ids.include?(account.id)
# Otherwise, filter replies to someone you've muted or blocked.
return true if filtered_reply
# Otherwise, filter the status if it mentions someone in the preloaded muting relation.
return true if @preloaded_relations[:muting] && mentioned_account_ids.any? do |mentioned_account_id|
@preloaded_relations[:muting][mentioned_account_id]
end
# Otherwise, filter the status if it mentions someone you've muted.
return true if account.muting?(mentioned_account_ids)
# Same as above, but for blocks:
return true if @preloaded_relations[:blocking] && mentioned_account_ids.any? do |mentioned_account_id|
@preloaded_relations[:blocking][mentioned_account_id]
end
account.blocking?(mentioned_account_ids)
end
def reply_to_blocked?
@preloaded_relations[:blocking] ? @preloaded_relations[:blocking][status.in_reply_to_account_id] : account.blocking?(status.in_reply_to_account_id)
end
def reply_to_muted?
@preloaded_relations[:muting] ? @preloaded_relations[:muting][status.in_reply_to_account_id] : account.muting?(status.in_reply_to_account_id)
end
def reply_to_no_replies?
status.reply? &&
!status.in_reply_to_account_id.nil? &&
!status.in_reply_to_id.nil? &&
status.account_id != status.in_reply_to_account_id &&
Status.find(status.in_reply_to_id)&.marked_no_replies?
end
def blocking_account?
@preloaded_relations[:blocking] ? @preloaded_relations[:blocking][status.account_id] : account.blocking?(status.account_id)
end
def blocking_domain?
@preloaded_relations[:domain_blocking_by_domain] ? @preloaded_relations[:domain_blocking_by_domain][status.account_domain] : account.domain_blocking?(status.account_domain)
end
def muting_account?
@preloaded_relations[:muting] ? @preloaded_relations[:muting][status.account_id] : account.muting?(status.account_id)
end
def silenced_account?
!account&.silenced? && status_account_silenced? && !account_following_status_account?
end
def status_account_silenced?
status.account.silenced?
end
def account_following_status_account?
@preloaded_relations[:following] ? @preloaded_relations[:following][status.account_id] : account&.following?(status.account_id)
end
def blocked_by_policy?
!policy_allows_show?
end
def policy_allows_show?
StatusPolicy.new(account, status, @preloaded_relations).show?
end
end
|