about summary refs log tree commit diff
path: root/app/models/keyword_mute.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/keyword_mute.rb')
-rw-r--r--app/models/keyword_mute.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/keyword_mute.rb b/app/models/keyword_mute.rb
index 8b54ad696..b0229923d 100644
--- a/app/models/keyword_mute.rb
+++ b/app/models/keyword_mute.rb
@@ -6,6 +6,7 @@
 #  id         :integer          not null, primary key
 #  account_id :integer          not null
 #  keyword    :string           not null
+#  whole_word :boolean          default(TRUE), not null
 #  created_at :datetime         not null
 #  updated_at :datetime         not null
 #
@@ -32,12 +33,13 @@ class KeywordMute < ApplicationRecord
 
     def initialize(account_id)
       re = [].tap do |arr|
-        KeywordMute.where(account_id: account_id).select(:keyword, :id).find_each do |m|
-          arr << Regexp.escape(m.keyword.strip)
+        KeywordMute.where(account_id: account_id).select(:keyword, :id, :whole_word).find_each do |m|
+          boundary = m.whole_word ? '\b' : ''
+          arr << "#{boundary}#{Regexp.escape(m.keyword.strip)}#{boundary}"
         end
       end.join('|')
 
-      @regex = /\b(?:#{re})\b/i unless re.empty?
+      @regex = /#{re}/i unless re.empty?
     end
 
     def =~(str)