keyword mutes: also check spoiler (CW) text and reblogged statuses.
This commit is contained in:
		
							parent
							
								
									b2ad79547c
								
							
						
					
					
						commit
						8d69329b8e
					
				
					 2 changed files with 37 additions and 7 deletions
				
			
		|  | @ -138,13 +138,11 @@ class FeedManager | |||
|   end | ||||
| 
 | ||||
|   def filter_from_home?(status, receiver_id) | ||||
|     keyword_mute_matcher = Glitch::KeywordMute.matcher_for(receiver_id) | ||||
| 
 | ||||
|     return true if keyword_mute_matcher =~ status.text | ||||
| 
 | ||||
|     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?) | ||||
| 
 | ||||
|     return true if keyword_filter?(status, Glitch::KeywordMute.matcher_for(receiver_id)) | ||||
| 
 | ||||
|     check_for_mutes = [status.account_id] | ||||
|     check_for_mutes.concat(status.mentions.pluck(:account_id)) | ||||
|     check_for_mutes.concat([status.reblog.account_id]) if status.reblog? | ||||
|  | @ -163,7 +161,6 @@ class FeedManager | |||
|       return should_filter | ||||
|     elsif status.reblog?                                                                                                 # Filter out a reblog | ||||
|       should_filter   = Block.where(account_id: status.reblog.account_id, target_account_id: receiver_id).exists?        # or if the author of the reblogged status is blocking me | ||||
|       should_filter ||= keyword_mute_matcher.matches?(status.reblog.text) | ||||
|       should_filter ||= AccountDomainBlock.where(account_id: receiver_id, domain: status.reblog.account.domain).exists?  # or the author's domain is blocked | ||||
|       return should_filter | ||||
|     end | ||||
|  | @ -171,6 +168,18 @@ class FeedManager | |||
|     false | ||||
|   end | ||||
| 
 | ||||
|   def keyword_filter?(status, matcher) | ||||
|     should_filter   = matcher =~ status.text | ||||
|     should_filter ||= matcher =~ status.spoiler_text | ||||
| 
 | ||||
|     if status.reblog? | ||||
|       should_filter ||= matcher =~ status.reblog.text | ||||
|       should_filter ||= matcher =~ status.reblog.spoiler_text | ||||
|     end | ||||
| 
 | ||||
|     should_filter | ||||
|   end | ||||
| 
 | ||||
|   def filter_from_mentions?(status, receiver_id) | ||||
|     return true if receiver_id == status.account_id | ||||
| 
 | ||||
|  |  | |||
|  | @ -122,20 +122,41 @@ RSpec.describe FeedManager do | |||
| 
 | ||||
|       it 'returns true for a status containing a muted keyword' do | ||||
|         Fabricate('Glitch::KeywordMute', account: alice, keyword: 'take') | ||||
|         alice.follow!(bob) | ||||
|         status = Fabricate(:status, text: 'This is a hot take', account: bob) | ||||
| 
 | ||||
|         expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true | ||||
|       end | ||||
| 
 | ||||
|       it 'returns true for a reply containing a muted keyword' do | ||||
|         Fabricate('Glitch::KeywordMute', account: alice, keyword: 'take') | ||||
|         s1 = Fabricate(:status, text: 'Something', account: alice) | ||||
|         s2 = Fabricate(:status, text: 'This is a hot take', thread: s1, account: bob) | ||||
| 
 | ||||
|         expect(FeedManager.instance.filter?(:home, s2, alice.id)).to be true | ||||
|       end | ||||
| 
 | ||||
|       it 'returns true for a status whose spoiler text contains a muted keyword' do | ||||
|         Fabricate('Glitch::KeywordMute', account: alice, keyword: 'take') | ||||
|         status = Fabricate(:status, spoiler_text: 'This is a hot take', account: bob) | ||||
| 
 | ||||
|         expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true | ||||
|       end | ||||
| 
 | ||||
|       it 'returns true for a reblog containing a muted keyword' do | ||||
|         Fabricate('Glitch::KeywordMute', account: alice, keyword: 'take') | ||||
|         alice.follow!(jeff) | ||||
|         status = Fabricate(:status, text: 'This is a hot take', account: bob) | ||||
|         reblog = Fabricate(:status, reblog: status, account: jeff) | ||||
| 
 | ||||
|         expect(FeedManager.instance.filter?(:home, reblog, alice.id)).to be true | ||||
|       end | ||||
| 
 | ||||
|       it 'returns true for a reblog whose spoiler text contains a muted keyword' do | ||||
|         Fabricate('Glitch::KeywordMute', account: alice, keyword: 'take') | ||||
|         status = Fabricate(:status, spoiler_text: 'This is a hot take', account: bob) | ||||
|         reblog = Fabricate(:status, reblog: status, account: jeff) | ||||
| 
 | ||||
|         expect(FeedManager.instance.filter?(:home, reblog, alice.id)).to be true | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|     context 'for mentions feed' do | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue