Skip to content

Commit

Permalink
Disable coloring of comments icon for comments created by user itself (
Browse files Browse the repository at this point in the history
…#515)

* disable coloring of comments icon for comments created by user itself

* avoid recreation of existing reader instances

* replace touch by update method to ensure validation

* adress the case of overlapping comments

* fix rubocop offenses
  • Loading branch information
fosterfarrell9 authored Jul 3, 2023
1 parent ba4b0f2 commit cd3016c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/controllers/commontator/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,25 @@ def update_unread_status
return unless medium.released.in?(['all', 'users', 'subscribers'])

relevant_users = medium.teachable.media_scope.users
relevant_users.where(unread_comments: false)
relevant_users.where.not(id: current_user.id)
.where(unread_comments: false)
.update_all(unread_comments: true)
@update_icon = relevant_users.exists?(current_user.id)

# make sure that the thread associated to this comment is marked as read
# by the comment creator (unless some other user posted a comment in it
# that has not yet been read)
@reader = Reader.find_or_create_by(user: current_user,
thread: @commontator_thread)
if unseen_comments?
@update_icon = true
return
end
@reader.update(updated_at: Time.current)
end

def unseen_comments?
@commontator_thread.comments.any? do |c|
c.creator != current_user && c.created_at > @reader.updated_at
end
end
end

0 comments on commit cd3016c

Please sign in to comment.