@@ -29,7 +29,7 @@ def create_thread
2929 @comment_thread = CommentThread . new ( title : title , post : @post )
3030 @comment = Comment . new ( post : @post , content : body , user : current_user , comment_thread : @comment_thread )
3131
32- pings = check_for_pings @comment_thread , body
32+ pings = check_for_pings ( @comment_thread , body )
3333
3434 success = ActiveRecord ::Base . transaction do
3535 thread_success = @comment_thread . save
@@ -56,7 +56,7 @@ def create_thread
5656 ThreadFollower . create ( user : tf . user , comment_thread : @comment_thread )
5757 end
5858
59- apply_pings pings
59+ apply_pings ( pings )
6060 else
6161 flash [ :danger ] = "Could not create comment thread: #{ ( @comment_thread . errors . full_messages \
6262 + @comment . errors . full_messages ) . join ( ', ' ) } "
@@ -66,15 +66,15 @@ def create_thread
6666
6767 def create
6868 body = params [ :content ]
69- pings = check_for_pings @comment_thread , body
69+ pings = check_for_pings ( @comment_thread , body )
7070
7171 @comment = Comment . new ( post : @post , content : body , user : current_user ,
7272 comment_thread : @comment_thread , has_reference : false )
7373
7474 status = @comment . save
7575
7676 if status
77- apply_pings pings
77+ apply_pings ( pings )
7878 @comment_thread . thread_follower . each do |follower |
7979 next if follower . user_id == current_user . id
8080 next if pings . include? follower . user_id
@@ -105,17 +105,18 @@ def update
105105 @post = @comment . post
106106 @comment_thread = @comment . comment_thread
107107 before = @comment . content
108- before_pings = check_for_pings @comment_thread , before
108+ before_pings = check_for_pings ( @comment_thread , before )
109109 if @comment . update comment_params
110110 unless current_user . id == @comment . user_id
111111 audit ( 'comment_update' , @comment , "from <<#{ before } >>\n to <<#{ @comment . content } >>" )
112112 end
113113
114- after_pings = check_for_pings @comment_thread , @comment . content
114+ after_pings = check_for_pings ( @comment_thread , @comment . content )
115115 apply_pings ( after_pings - before_pings - @comment_thread . thread_follower . to_a )
116116
117117 render json : { status : 'success' ,
118- comment : render_to_string ( partial : 'comments/comment' , locals : { comment : @comment } ) }
118+ comment : render_to_string ( partial : 'comments/comment' ,
119+ locals : { comment : @comment , pingable : after_pings } ) }
119120 else
120121 render json : { status : 'failed' ,
121122 message : "Comment failed to save (#{ @comment . errors . full_messages . join ( ', ' ) } )" } ,
@@ -279,8 +280,7 @@ def post_follow
279280
280281 def pingable
281282 thread = params [ :id ] == '-1' ? CommentThread . new ( post_id : params [ :post ] ) : CommentThread . find ( params [ :id ] )
282- ids = helpers . get_pingable ( thread )
283- users = User . where ( id : ids )
283+ users = User . where ( id : thread . pingable )
284284 render json : users . to_h { |u | [ u . username , u . id ] }
285285 end
286286
@@ -379,12 +379,16 @@ def check_if_target_post_locked
379379 check_if_locked ( Post . find ( params [ :post_id ] ) )
380380 end
381381
382+ # @param thread [CommentThread] thread to extract pings for
383+ # @param content [String] content to extract pings from
384+ # @return [Array<Integer>] list of pinged user ids
382385 def check_for_pings ( thread , content )
383- pingable = helpers . get_pingable ( thread )
386+ pingable = thread . pingable
384387 matches = content . scan ( /@#(\d +)/ )
385388 matches . flatten . select { |m | pingable . include? ( m . to_i ) } . map ( &:to_i )
386389 end
387390
391+ # @param pings [Array<Integer>] list of pinged user ids
388392 def apply_pings ( pings )
389393 pings . each do |p |
390394 user = User . where ( id : p ) . first
0 commit comments