Right now, when you view a node all of its new comments are suddenly treated as no longer new. This makes it essentially impossible to keep track of which comments on a node you've already seen. The status of a comment, i.e., whether you've seen it or not, should be independent of the status of the node.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jik’s picture

FileSize
7.79 KB

The attached patch for your evaluation implements this functionality.

The one aspect of the patch that I'm concerned about is that I chose to implement the "read comments" table using ranges rather than recording a single comment in each row, to keep the size of the table small. My concern is that since I'm using ranges, hashes can't be used directly to search the table, so performance will be bad when it gets large.

jik’s picture

FileSize
6.06 KB

Here's a better patch for comment.module. The rest of my last patch remains unchanged.

jik’s picture

jik’s picture

FileSize
15.13 KB

Here's a new patch against 4.4.0-rc, which also incorporates my patches for forums list should show new comments and add new "new expanded" comment display modes, since they are all interrelated and it's too hard to separate them now that I've ported all my patches to 4.4.0-rc.

jik’s picture

FileSize
482 bytes

Found a bug. Here's an additional patch on top of the last one.

jik’s picture

FileSize
1.05 KB

Another bug. When I added code for purging old entries from comments_history, I forgot to take that into account in comment_num_new and comment_is_new. Patch attached.

jik’s picture

FileSize
1.41 KB

Another patch, to make it possible to view a comment without marking it read. We use this to display unpublished comments for moderators so that they can approve comments without changing the system's indication of whether they've read them (so they can easily read them in context later).

jik’s picture

FileSize
532 bytes

Another patch. This is just a bit of paranoia in the code that removes old entries from the comment history.

jik’s picture

FileSize
234 bytes

Yet another patch. Shouldn't try to mark a comment read if the comment ID is 0 (i.e., we're previewing a comment that doesn't exist yet!)

jik’s picture

FileSize
678 bytes

Yet another patch to fix a precedence error in an SQL statement.

moshe weitzman’s picture

The policy here is that the latest patch in the issue should be complete. A reviewer will not look at all the patches posted and figure out which ones add up to the functionality desired.

Furthermore, when one posts more than a few patches for the same issue, he may give the reviewer the impression that he is not properly testing his code before upload. reputation is key in getting the attention/trust of the review team.

ixis.dylan’s picture

This is still causing problems for my users, as only comments on the first page are flagged as new. Has anybody tried to fix this?

catch’s picture

Title: new status for comments should be tracked separately from status for node » All comments marked as read when viewing any page.
Version: » 7.x-dev
Category: feature » bug
Status: Active » Needs work
Crimson’s picture

An issue 3 years in the making and it's not fixed yet? :P I think this is important enough to warrant some looking at.

catch’s picture

Well the main issue seems to be that comment display is pretty much handled by the node module - comments don't have any real presence in their own right when displayed (and therefore to be marked as read or not). There's a few issues around where the solution proposed has been a rewrite of the comment module to fix this underlying issue, which is quite a big one in terms of the architecture of that particular module. My site (volunteer/donation run) is looking into fundraising for this for D7, probably the best place to discuss that would be: http://groups.drupal.org/drubb - although not much point until Drupal 6 is released.

Crimson’s picture

Thanks for the link. I'll join the group to see the progression of forum features, which this bug report is for, at its core.

catch’s picture

R.Muilwijk’s picture

I would not mind rerolling the patch against current head. However, I would like to know or the proposed patch is the solution we want.

drunken monkey’s picture

Status: Needs work » Needs review

Has this really been around for 6.5 years? It works here on d.o, so this doesn't seem likely …
However, ran into this today myself, so something really seems to be wrong. The attached patch would be an easy fix.
Additionally fixes some suboptimal checks on $node->comment in comment_node_view() – these are (or should be) only of cosmetic nature, but are still a bit WTF for core code. The only relevant bit are the few lines in node_show().

drunken monkey’s picture

FileSize
2.98 KB
drunken monkey’s picture

Status: Needs review » Needs work

The last submitted patch, comments_marked_read.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review

#21: comments_marked_read.patch queued for re-testing.

Sorry, can't reproduce this test fail locally. :-/ And since the line where it happens isn't particularly helpful I'd rather be sure there is a bug …

Can someone else reproduce the test fail? ("Comment interface" is the one I modified, so would probably also be the culprit here.) And, in that case, tell me in which test method / line the fail occurs?

Status: Needs review » Needs work

The last submitted patch, comments_marked_read.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review
FileSize
4.92 KB

Then maybe like this?

peterpoe’s picture

There's an attempt to solve the issue also here #983632: New comment marker does not work. Maybe the two patches can be merged?
drunken monkey, what is the reasoning behind these changes?

-  if ($node->comment) {
+  if ($node->comment != COMMENT_NODE_HIDDEN) {
-    if ($node->comment && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview) && user_access('access comments')) {
+    if ($view_mode == 'full' && node_is_page($node) && empty($node->in_preview) && user_access('access comments')) {
drunken monkey’s picture

The first is just better style (there is a COMMENT_NODE_HIDDEN constant for a reason) — and also, the same if clause was completely unnecessarily two lines beneath that, so I just "merged" them.
In the second, the $node->comment part of the boolean expression is completely unnecessary, as this was already tested above (in an enclosing if).

Both have nothing to do with this issue, of course, but some time this should be corrected anyways.

#25: comments_marked_read.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, comments_marked_read.patch, failed testing.

peterpoe’s picture

Test fails since there are other bugs involved, see #983632: New comment marker does not work.

drunken monkey’s picture

Dear god, what in the whole "new comments" system does even work … ?

Maybe we should merge these two issues, so both can be fixed and tested at once?

catch’s picture

I don't think we should merge these. As far as I can see there are (at least) two bugs:

First a regression from D6, where all comments get marked read before you even get a chance to look a them.

Second, this original bug, where viewing comments is based on when you last viewed the node, not taking into account paging of comments - to handle that effectively would require a major refactoring of comment module and it's Drupal 8 material at this point.

InternetDevels’s picture

We had similar problem. When users view any nodes all comments marked as read.
This occurs because database 'history' table updated before comments rendering (function node_show that called in 'node_page_view' page callback for menu item 'node/%node').

We have fixed this in next way:

/**
 * Implementation of hook_menu_later
 */
function mymodule_menu_alter(&$items) {
  $items['node/%node']['page callback'] = 'mymodule_node_page_view';
  
}

/**
 * callback for node view
 */
function mymodule_node_page_view($node) {
  // read last page view timestamp before {history} table updated
  // timestamp will saved in central static storage (drupal_static)
  node_last_viewed($node->nid);
  return node_page_view($node);
}
catch’s picture

That's a different bug, the patch at #983632: New comment marker does not work should fix that.

The issue here is that if you have ten pages of comments, visiting any of those pages marks the other nine pages as read too.

dixon_’s picture

Version: 7.x-dev » 8.x-dev

This still applies to 8.x

bleen’s picture

Google reader handles this by using javascript and AJAX to mark an item as read only when it is in the viewport. This is visually indicated to the user by highlighting the item wrapper with a dark border while it's being "read" (thus truggering the state change). IMO this is the most accurate reflection of what a user actually expects. I'm not sure what the corresponding non-ajax behavior would be here, but I think this is worth exploring.

star-szr’s picture

mototribe’s picture

We came up with this workaround - we setup a page at node/[nid]/new to check for new comments and redirect to the correct page at node/[nid]?page=[page]#new

  $items['node/%node/new'] = array(
    'title' => 'New comments',
    'access arguments' => array('access content'),
    'page callback' => 'my_custom_node_new_comments_redirect',
    'page arguments' => array(1),
  );

/**
 * Callback for node/%/new. Forward to latest new comments page.
 */
function my_custom_node_new_comments_redirect($node) {
  $options = array('fragment' => 'new');

  // The page will only ever change for authenticated users.
  if (user_is_logged_in()) {
    if ($new = comment_num_new($node->nid)) {
      $options['query'] = comment_new_page_count($node->comment_count, $new, $node);
    }
  }

  drupal_goto("node/$node->nid", $options);
}

mikhailian’s picture

Status: Needs work » Needs review

25: comments_marked_read.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 25: comments_marked_read.patch, failed testing.

larowlan’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

This isn't something we're going to fix in core.
It can be handled in contrib with a custom formatter and JavaScript if it is important enough to a particular custom project.