Skip to content

Commit

Permalink
Reapply first fix for Reader/Media
Browse files Browse the repository at this point in the history
See discussion on #574 for further details.
Previous PR for this was #576, closed in favor of this one
as this directly branches off the new "dev" branch.
  • Loading branch information
Splines committed Jan 8, 2024
1 parent c769834 commit dd7d0a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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

0 comments on commit dd7d0a1

Please sign in to comment.