Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unread comments status (new trial) #576

Closed
wants to merge 13 commits into from
5 changes: 3 additions & 2 deletions app/controllers/commontator/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ def update_unread_status
# 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)
@reader = Reader.find_by(user: current_user, thread: @commontator_thread)
return unless @reader

if unseen_comments?
@update_icon = true
return
Expand Down
20 changes: 13 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,20 @@ def subscribed_commentable_media_with_comments
end

def media_latest_comments
media = subscribed_commentable_media_with_comments
.map do |m|
{ medium: m,
thread: m.commontator_thread,
latest_comment: m.commontator_thread
.comments.max_by(&:created_at) }
relevant_media = []

subscribed_commentable_media_with_comments.each do |m|
latest_comment = m.commontator_thread.comments
.reject { |c| c.creator == self }
.max_by(&:created_at)
next unless latest_comment

relevant_media << { medium: m,
thread: m.commontator_thread,
latest_comment: latest_comment }
end
media.sort_by { |x| x[:latest_comment].created_at }.reverse

relevant_media.sort_by { |x| x[:latest_comment].created_at }.reverse
end

# lecture that are in the active term
Expand Down