@@ -20,7 +20,7 @@ class AlreadyFlagged < StandardError; end
2020
2121 def self . update_flagged_posts_count
2222 posts_flagged_count = PostAction . joins ( post : :topic )
23- . where ( 'post_actions.post_action_type_id' => PostActionType . FlagTypes ,
23+ . where ( 'post_actions.post_action_type_id' => PostActionType . flag_types . values ,
2424 'posts.deleted_at' => nil ,
2525 'topics.deleted_at' => nil ) . count ( 'DISTINCT posts.id' )
2626
@@ -55,13 +55,12 @@ def self.clear_flags!(post, moderator_id, action_type_id = nil)
5555 actions = if action_type_id
5656 [ action_type_id ]
5757 else
58- moderator_id == -1 ? PostActionType . AutoActionFlagTypes : PostActionType . FlagTypes
58+ moderator_id == -1 ? PostActionType . auto_action_flag_types . values : PostActionType . flag_types . values
5959 end
6060
6161 PostAction . update_all ( { deleted_at : Time . now , deleted_by : moderator_id } , { post_id : post . id , post_action_type_id : actions } )
6262
63- r = PostActionType . Types . invert
64- f = actions . map { |t | [ "#{ r [ t ] } _count" , 0 ] }
63+ f = actions . map { |t | [ "#{ PostActionType . types [ t ] } _count" , 0 ] }
6564
6665 Post . with_deleted . update_all ( Hash [ *f . flatten ] , id : post . id )
6766
@@ -87,15 +86,15 @@ def self.remove_act(user, post, post_action_type_id)
8786 end
8887
8988 def is_bookmark?
90- post_action_type_id == PostActionType . Types [ :bookmark ]
89+ post_action_type_id == PostActionType . types [ :bookmark ]
9190 end
9291
9392 def is_like?
94- post_action_type_id == PostActionType . Types [ :like ]
93+ post_action_type_id == PostActionType . types [ :like ]
9594 end
9695
9796 def is_flag?
98- PostActionType . FlagTypes . include? ( post_action_type_id )
97+ PostActionType . flag_types . values . include? ( post_action_type_id )
9998 end
10099
101100 # A custom rate limiter for this model
@@ -124,15 +123,15 @@ def message_quality
124123 end
125124
126125 before_create do
127- raise AlreadyFlagged if is_flag? && PostAction . where ( user_id : user_id ,
128- post_id : post_id ,
129- post_action_type_id : PostActionType . FlagTypes ) . exists?
126+ raise AlreadyFlagged if is_flag? and PostAction . where ( user_id : user_id ,
127+ post_id : post_id ,
128+ post_action_type_id : PostActionType . flag_types . values ) . exists?
130129 end
131130
132131 after_save do
133132 # Update denormalized counts
134- post_action_type = PostActionType . Types . invert [ post_action_type_id ]
135- column = "#{ post_action_type } _count"
133+ post_action_type = PostActionType . types [ post_action_type_id ]
134+ column = "#{ post_action_type . to_s } _count"
136135 delta = deleted_at . nil? ? 1 : -1
137136
138137 # Voting also changes the sort_order
@@ -144,7 +143,7 @@ def message_quality
144143 Topic . update_all [ "#{ column } = #{ column } + ?" , delta ] , id : post . topic_id
145144
146145
147- if PostActionType . FlagTypes . include? ( post_action_type_id )
146+ if PostActionType . flag_types . values . include? ( post_action_type_id )
148147 PostAction . update_flagged_posts_count
149148 end
150149
@@ -153,7 +152,7 @@ def message_quality
153152 flag_counts = exec_sql ( "SELECT SUM(CASE WHEN deleted_at IS NULL THEN 1 ELSE 0 END) AS new_flags,
154153 SUM(CASE WHEN deleted_at IS NOT NULL THEN 1 ELSE 0 END) AS old_flags
155154 FROM post_actions
156- WHERE post_id = ? AND post_action_type_id IN (?)" , post . id , PostActionType . AutoActionFlagTypes ) . first
155+ WHERE post_id = ? AND post_action_type_id IN (?)" , post . id , PostActionType . auto_action_flag_types . values ) . first
157156 old_flags , new_flags = flag_counts [ 'old_flags' ] . to_i , flag_counts [ 'new_flags' ] . to_i
158157
159158 if new_flags >= SiteSetting . flags_required_to_hide_post
0 commit comments