-
Notifications
You must be signed in to change notification settings - Fork 10
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 #574
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,18 +209,22 @@ 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) | ||
if unseen_comments? | ||
reader = Reader.find_or_create_by(user: current_user, | ||
thread: @commontator_thread) | ||
if unseen_new_comments?(reader) | ||
@update_icon = true | ||
return | ||
end | ||
@reader.touch | ||
reader.touch | ||
return if current_user.unread_media_comments.any? | ||
|
||
current_user.update(unread_comments: false) | ||
@no_unread_comments = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how this achieves the goal of this PR. Right now, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏺ Update Maybe I get it now. That's why we need another method to find out if the user generally has any unseen comments and this is the We don't want to execute this rather costly operation of searching all unread comments on every pageload to determine which color the bubble should have, right? That's why we have the If what I said is correct so far I'm still not sure why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's it exactly.
That is precisely the logic we had before we introduced #515 (and which we did not change in #515), see the raeders_controller which does exactly what you describe and resets the |
||
end | ||
|
||
def unseen_comments? | ||
def unseen_new_comments?(reader) | ||
@commontator_thread.comments.any? do |c| | ||
c.creator != current_user && c.created_at > @reader.updated_at | ||
c.creator != current_user && c.created_at > reader.updated_at | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -774,6 +774,14 @@ def last_sign_in_ip=(_ip) | |
def current_sign_in_ip=(_ip) | ||
end | ||
|
||
def unread_media_comments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Furthermore, I'm not too sure if the user model is the place where this methods belongs to as it is related to the comments and not the user itself. But this is a problem generally with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the gneral sentiment towards |
||
media_latest_comments.select do |mc| | ||
(Reader.find_by(user: self, thread: mc[:thread]) | ||
&.updated_at || 1000.years.ago) < mc[:latest_comment].created_at && | ||
Comment on lines
+779
to
+780
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract expression to variable, then use it to do the comparison. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also note that a very similar logic is used in the |
||
mc[:medium].visible_for_user?(self) | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_defaults | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,28 @@ | |
%> | ||
|
||
<% if @commontator_new_comment.nil? %> | ||
$("#<%= id %>").hide(); | ||
$("#<%= id %>").hide(); | ||
|
||
$("#<%= id %>-link").fadeIn(); | ||
$("#<%= id %>-link").fadeIn(); | ||
<% else %> | ||
$("#<%= id %>").html("<%= escape_javascript( | ||
$("#<%= id %>").html("<%= escape_javascript( | ||
render partial: 'form', locals: { | ||
comment: @commontator_new_comment, thread: @commontator_thread | ||
} | ||
) %>"); | ||
<% end %> | ||
|
||
<% if @update_icon %> | ||
$('#commentsIcon').addClass('new-comment'); | ||
$("#commentsIcon").addClass("new-comment"); | ||
<% end %> | ||
|
||
<% if @no_unread_comments %> | ||
$("#commentsIcon").removeClass("new-comment"); | ||
<% end %> | ||
Comment on lines
32
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the flow inside the But still, maybe we can simplify the logic in the controller such that the frontend only has to deal with one variable determining whether to add the CSS class or do nothing? Or do we really have to remove the CSS class because it is set in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The navbar is loaded way before. In the situation described in #573, the teacher finds a yellow new_comments icon in the navbar (correctly so), posts their reply, and then the icon has to turn white. During that process, the navbar does not get reloaded. The alternative to what is done in the PR would be to reload the navbar. But the view we have here is a view of the commontator gem which we modify (currently only by the two simple simple statements). Reloading the navbar would be a bigger operation which I suggest we keep out of this "external" view. |
||
|
||
var commontatorComment = $("#commontator-comment-<%= @comment.id %>").hide().fadeIn(); | ||
$('html, body').animate( | ||
{ scrollTop: commontatorComment.offset().top - window.innerHeight/2 }, 'fast' | ||
$("html, body").animate( | ||
{ scrollTop: commontatorComment.offset().top - window.innerHeight / 2 }, "fast", | ||
); | ||
|
||
<%= javascript_proc %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this in the last PR. Why do we need a global variable here (
@reader
)? Instead, pass the reader tounseen_comments
as parameter. This way it's even easier to understand what is going on. A smiliar scenario can be found in theupdate
method inreaders_controller
.