Skip to content

Commit 3afcb12

Browse files
committed
Move followed_by? method to post model to simplify calling
(cherry picked from commit 2dc9035)
1 parent 2edf7b6 commit 3afcb12

4 files changed

Lines changed: 9 additions & 2 deletions

File tree

app/controllers/comments_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def post
276276

277277
def post_follow
278278
@post = Post.find(params[:post_id])
279-
if CommentThread.post_followed?(@post, current_user)
279+
if @post.followed_by?(current_user)
280280
ThreadFollower.where(post: @post, user: current_user).destroy_all
281281
else
282282
ThreadFollower.create(post: @post, user: current_user)

app/models/comment_thread.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def can_access?(user)
4444
(!deleted? || user&.privilege?('flag_curate') || user&.post_privilege?('flag_curate', post)) &&
4545
post.can_access?(user)
4646
end
47+
<<<<<<< HEAD
4748

4849
# Gets a list of user IDs who should be pingable in the thread.
4950
# @return [Array<Integer>]
@@ -85,4 +86,6 @@ def create_follower
8586
ThreadFollower.create comment_thread: self, user: post.user
8687
end
8788
end
89+
=======
90+
>>>>>>> 2dc90352 (Move followed_by? method to post model to simplify calling)
8891
end

app/models/post.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def reaction_list
234234
.to_h { |_k, v| [v.first.reaction_type, v] }
235235
end
236236

237+
def followed_by?(user)
238+
ThreadFollower.where(post: self, user: user).any?
239+
end
240+
237241
private
238242

239243
##

app/views/posts/_expanded.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
<%= pluralize(public_count, 'comment thread') %>
533533
</h4>
534534
<% if user_signed_in? %>
535-
<% if CommentThread.post_followed?(post, current_user) %>
535+
<% if post.followed_by?(current_user) %>
536536
<%= link_to follow_post_comments_path(post_id: post.id), method: :post,
537537
class: "button is-muted is-outlined is-small",
538538
title: 'Don\'t follow new comment threads on this post',

0 commit comments

Comments
 (0)