Class: PostActionTypeView
- Inherits:
-
Object
- Object
- PostActionTypeView
- Defined in:
- lib/post_action_type_view.rb
Constant Summary collapse
- ATTRIBUTE_NAMES =
%i[ id name name_key description notify_type auto_action_type require_message applies_to position enabled score_type ]
Instance Method Summary collapse
- #additional_message_types ⇒ Object
- #all_flags ⇒ Object
- #applies_to ⇒ Object
- #auto_action_flag_types ⇒ Object
- #descriptions ⇒ Object
- #disabled_flag_types ⇒ Object
- #flag_settings ⇒ Object
- #flag_types ⇒ Object
- #flag_types_without_additional_message ⇒ Object
- #flags ⇒ Object
- #is_flag?(sym) ⇒ Boolean
- #names ⇒ Object
-
#notify_flag_type_ids ⇒ Object
flags resulting in mod notifications.
- #notify_flag_types ⇒ Object
- #overridden_by_plugin_or_skipped_db? ⇒ Boolean
- #public_type_ids ⇒ Object
- #public_types ⇒ Object
- #score_types ⇒ Object
- #topic_flag_types ⇒ Object
- #types ⇒ Object
Instance Method Details
#additional_message_types ⇒ Object
104 105 106 107 |
# File 'lib/post_action_type_view.rb', line 104 def return flag_settings. if overridden_by_plugin_or_skipped_db? flag_enum(all_flags.select { |flag| flag[:require_message] }) end |
#all_flags ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/post_action_type_view.rb', line 18 def all_flags @all_flags ||= Discourse .cache .fetch(PostActionType::POST_ACTION_TYPE_ALL_FLAGS_KEY) do Flag .unscoped .order(:position) .pluck(ATTRIBUTE_NAMES) .map { |attributes| ATTRIBUTE_NAMES.zip(attributes).to_h } end end |
#applies_to ⇒ Object
123 124 125 126 127 128 |
# File 'lib/post_action_type_view.rb', line 123 def applies_to all_flags.reduce({}) do |acc, f| acc[f[:id]] = f[:applies_to] acc end end |
#auto_action_flag_types ⇒ Object
46 47 48 49 |
# File 'lib/post_action_type_view.rb', line 46 def auto_action_flag_types return flag_settings.auto_action_types if overridden_by_plugin_or_skipped_db? flag_enum(all_flags.select { |flag| flag[:auto_action_type] }) end |
#descriptions ⇒ Object
116 117 118 119 120 121 |
# File 'lib/post_action_type_view.rb', line 116 def descriptions all_flags.reduce({}) do |acc, f| acc[f[:id]] = f[:description] acc end end |
#disabled_flag_types ⇒ Object
100 101 102 |
# File 'lib/post_action_type_view.rb', line 100 def disabled_flag_types flag_enum(all_flags.reject { |flag| flag[:enabled] }) end |
#flag_settings ⇒ Object
31 32 33 |
# File 'lib/post_action_type_view.rb', line 31 def flag_settings @flag_settings ||= PostActionType.flag_settings end |
#flag_types ⇒ Object
72 73 74 75 |
# File 'lib/post_action_type_view.rb', line 72 def flag_types return flag_settings.flag_types if overridden_by_plugin_or_skipped_db? flag_enum(flags) end |
#flag_types_without_additional_message ⇒ Object
61 62 63 64 |
# File 'lib/post_action_type_view.rb', line 61 def return flag_settings. if overridden_by_plugin_or_skipped_db? flag_enum(flags.reject { |flag| flag[:require_message] }) end |
#flags ⇒ Object
66 67 68 69 70 |
# File 'lib/post_action_type_view.rb', line 66 def flags all_flags.reject do |flag| flag[:score_type] || flag[:id] == PostActionType::LIKE_POST_ACTION_ID end end |
#is_flag?(sym) ⇒ Boolean
130 131 132 |
# File 'lib/post_action_type_view.rb', line 130 def is_flag?(sym) flag_types.valid?(sym) end |
#names ⇒ Object
109 110 111 112 113 114 |
# File 'lib/post_action_type_view.rb', line 109 def names all_flags.reduce({}) do |acc, f| acc[f[:id]] = f[:name] acc end end |
#notify_flag_type_ids ⇒ Object
flags resulting in mod notifications
83 84 85 |
# File 'lib/post_action_type_view.rb', line 83 def notify_flag_type_ids notify_flag_types.values end |
#notify_flag_types ⇒ Object
87 88 89 90 |
# File 'lib/post_action_type_view.rb', line 87 def notify_flag_types return flag_settings.notify_types if overridden_by_plugin_or_skipped_db? flag_enum(all_flags.select { |flag| flag[:notify_type] }) end |
#overridden_by_plugin_or_skipped_db? ⇒ Boolean
42 43 44 |
# File 'lib/post_action_type_view.rb', line 42 def overridden_by_plugin_or_skipped_db? flag_settings.flag_types.present? || GlobalSetting.skip_db? end |
#public_type_ids ⇒ Object
55 56 57 58 59 |
# File 'lib/post_action_type_view.rb', line 55 def public_type_ids Discourse .cache .fetch(PostActionType::POST_ACTION_TYPE_PUBLIC_TYPE_IDS_KEY) { public_types.values } end |
#public_types ⇒ Object
51 52 53 |
# File 'lib/post_action_type_view.rb', line 51 def public_types types.except(*flag_types.keys << :notify_user) end |
#score_types ⇒ Object
77 78 79 80 |
# File 'lib/post_action_type_view.rb', line 77 def score_types return flag_settings.flag_types if overridden_by_plugin_or_skipped_db? flag_enum(all_flags.filter { |flag| flag[:score_type] }) end |
#topic_flag_types ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/post_action_type_view.rb', line 92 def topic_flag_types if overridden_by_plugin_or_skipped_db? flag_settings.topic_flag_types else flag_enum(all_flags.select { |flag| flag[:applies_to].include?("Topic") }) end end |
#types ⇒ Object
35 36 37 38 39 40 |
# File 'lib/post_action_type_view.rb', line 35 def types if overridden_by_plugin_or_skipped_db? return Enum.new(like: PostActionType::LIKE_POST_ACTION_ID).merge!(flag_settings.flag_types) end Enum.new(like: PostActionType::LIKE_POST_ACTION_ID).merge(flag_types) end |