Progress
hashtag in top of tag feed, scroll to comment, chat blocking, muting, filtering
This commit is contained in:
@@ -17,9 +17,12 @@ class FeedManager
|
||||
"feed:#{type}:#{id}:#{subtype}"
|
||||
end
|
||||
|
||||
# status or chatMessage
|
||||
def filter?(timeline_type, status, receiver_id)
|
||||
if timeline_type == :home
|
||||
filter_from_home?(status, receiver_id)
|
||||
elsif timeline_type == :chat_message
|
||||
filter_from_chat_messages?(status, receiver_id)
|
||||
elsif timeline_type == :mentions
|
||||
filter_from_mentions?(status, receiver_id)
|
||||
else
|
||||
@@ -140,6 +143,10 @@ class FeedManager
|
||||
(context == :home ? Mute.where(account_id: receiver_id, target_account_id: account_ids).any? : Mute.where(account_id: receiver_id, target_account_id: account_ids, hide_notifications: true).any?)
|
||||
end
|
||||
|
||||
def chat_blocks?(receiver_id, account_ids)
|
||||
ChatBlock.where(account_id: receiver_id, target_account_id: account_ids).any?
|
||||
end
|
||||
|
||||
def filter_from_home?(status, receiver_id)
|
||||
return false if receiver_id == status.account_id
|
||||
return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
|
||||
@@ -170,6 +177,18 @@ class FeedManager
|
||||
false
|
||||
end
|
||||
|
||||
def filter_from_chat_messages?(chat_message, receiver_id)
|
||||
return false if receiver_id == chat_message.from_account_id
|
||||
return true if phrase_filtered_from_chat_message?(chat_message, receiver_id, :thread)
|
||||
|
||||
check_for_blocks = [chat_message.from_account_id]
|
||||
|
||||
return true if blocks_or_mutes?(receiver_id, check_for_blocks, :home)
|
||||
return true if chat_blocks?(receiver_id, check_for_blocks)
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def filter_from_mentions?(status, receiver_id)
|
||||
return true if receiver_id == status.account_id
|
||||
return true if phrase_filtered?(status, receiver_id, :notifications)
|
||||
@@ -211,6 +230,29 @@ class FeedManager
|
||||
(status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?)
|
||||
end
|
||||
|
||||
def phrase_filtered_from_chat_message?(chat_message, receiver_id, context)
|
||||
active_filters = Rails.cache.fetch("filters:#{receiver_id}") { CustomFilter.where(account_id: receiver_id).active_irreversible.to_a }.to_a
|
||||
|
||||
active_filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
|
||||
|
||||
active_filters.map! do |filter|
|
||||
if filter.whole_word
|
||||
sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
|
||||
eb = filter.phrase =~ /[[:word:]]\z/ ? '\b' : ''
|
||||
|
||||
/(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/
|
||||
else
|
||||
/#{Regexp.escape(filter.phrase)}/i
|
||||
end
|
||||
end
|
||||
|
||||
return false if active_filters.empty?
|
||||
|
||||
combined_regex = active_filters.reduce { |memo, obj| Regexp.union(memo, obj) }
|
||||
|
||||
!combined_regex.match(chat_message.text).nil?
|
||||
end
|
||||
|
||||
# Adds a status to an account's feed, returning true if a status was
|
||||
# added, and false if it was not added to the feed. Note that this is
|
||||
# an internal helper: callers must call trim or push updates if
|
||||
|
||||
Reference in New Issue
Block a user