2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-28 16:56:44 -04:00
|
|
|
class WatchedWordListSerializer < ApplicationSerializer
|
2021-05-27 12:20:26 -04:00
|
|
|
attributes :actions, :words, :compiled_regular_expressions
|
2017-06-28 16:56:44 -04:00
|
|
|
|
|
|
|
def actions
|
2021-05-14 09:52:10 -04:00
|
|
|
if SiteSetting.tagging_enabled
|
|
|
|
WatchedWord.actions.keys
|
2023-01-09 07:20:10 -05:00
|
|
|
else
|
2021-05-14 09:52:10 -04:00
|
|
|
WatchedWord.actions.keys.filter { |k| k != :tag }
|
2023-01-09 07:20:10 -05:00
|
|
|
end
|
2017-06-28 16:56:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def words
|
|
|
|
object.map { |word| WatchedWordSerializer.new(word, root: false) }
|
|
|
|
end
|
2017-09-27 15:48:57 -04:00
|
|
|
|
2019-08-02 05:53:03 -04:00
|
|
|
def compiled_regular_expressions
|
|
|
|
expressions = {}
|
2021-05-14 09:52:10 -04:00
|
|
|
actions.each do |action|
|
2023-11-01 10:41:10 -04:00
|
|
|
expressions[action] = WordWatcher.serialized_regexps_for_action(action, engine: :js)
|
2019-08-02 05:53:03 -04:00
|
|
|
end
|
|
|
|
expressions
|
|
|
|
end
|
2017-06-28 16:56:44 -04:00
|
|
|
end
|