--- ./database/database.mysql 2003/12/18 20:43:45 1.1 +++ ./database/database.mysql 2004/03/11 04:20:24 @@ -133,6 +133,17 @@ ) TYPE=MyISAM; -- +-- Table structure for table `comments_history` +-- + +CREATE TABLE comments_history ( + uid int(10) NOT NULL default '0', + min_cid int(10) NOT NULL default '0', + max_cid int(10) NOT NULL default '0', + KEY (uid) +) TYPE=MyISAM; + +-- -- Table structure for table 'directory' -- --- ./modules/comment.module 2004/03/11 02:40:56 1.2 +++ ./modules/comment.module 2004/03/11 05:26:38 @@ -541,7 +541,7 @@ ** Switch to folded/unfolded view of the comment */ - if (node_is_new($comment->nid, $comment->timestamp)) { + if (comment_is_new($comment->cid)) { $comment->new = 1; print "\n"; } @@ -551,6 +551,7 @@ if ($visible) { $comment->comment = check_output($comment->comment); theme("comment", $comment, $links); + comment_tag_new($comment->cid); } else { theme("comment_folded", $comment); @@ -1004,7 +1005,7 @@ $result = pager_query($sql, 50); while ($comment = db_fetch_object($result)) { - $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."". format_date($comment->timestamp, "small") ."". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); + $rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid", array("title" => htmlspecialchars(substr($comment->comment, 0, 128)))) ." ". (comment_is_new($comment->cid) ? theme_mark() : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."". format_date($comment->timestamp, "small") ."". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid")); } if ($pager = pager_display(NULL, 50, 0, "admin", tablesort_pager())) { @@ -1368,6 +1369,7 @@ $output .= "
$links
"; $output .= ""; print $output; + comment_tag_new($comment->cid); } function comment_folded($comment) { @@ -1526,32 +1528,32 @@ * @param $nid node-id to count comments for * @param $timestamp time to count from (defaults to time of last user access to node) */ -function comment_num_new($nid, $timestamp = 0) { - global $user; - - if ($user->uid) { - /* - ** Retrieve the timestamp at which the current user last viewed the - ** specified node. - */ - - if (!$timestamp) { - $timestamp = node_last_viewed($nid); - } +// function comment_num_new($nid, $timestamp = 0) { +// global $user; - /* - ** Use the timestamp to retrieve the number of new comments - */ - - $result = db_result(db_query("SELECT COUNT(c.cid) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp)); - - return $result; - } - else { - return 0; - } +// if ($user->uid) { +// /* +// ** Retrieve the timestamp at which the current user last viewed the +// ** specified node. +// */ + +// if (!$timestamp) { +// $timestamp = node_last_viewed($nid); +// } + +// /* +// ** Use the timestamp to retrieve the number of new comments +// */ + +// $result = db_result(db_query("SELECT COUNT(c.cid) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp)); + +// return $result; +// } +// else { +// return 0; +// } -} +// } function comment_user_can_moderate($node) { global $user; @@ -1662,4 +1664,102 @@ return array(1 => t("Date - newest first"), 2 => t("Date - oldest first")); } +function comment_tag_new($cid) { + global $user; + + if (! $user->uid) { + return; + } + + $result = db_query("SELECT uid FROM {comments_history} WHERE uid = %d AND min_cid <= %d and max_cid >= %d", $user->uid, $cid, $cid); + if (db_fetch_object($result)) { + return; + } + + db_query("UPDATE {comments_history} SET min_cid = %d where uid = %d AND min_cid = %d", $cid, $user->uid, $cid + 1); + if (db_affected_rows()) { + return; + } + + db_query("UPDATE {comments_history} SET max_cid = %d where uid = %d AND max_cid = %d", $cid, $user->uid, $cid - 1); + if (db_affected_rows()) { + return; + } + + db_query("INSERT INTO {comments_history} (uid, min_cid, max_cid) VALUES (%d, %d, %d)", $user->uid, $cid, $cid); +} + +function comment_is_new($cid) { + global $user; + + if (! $user->uid) { + return false; + } + + $result = db_query("SELECT * FROM {comments_history} where uid = %d and min_cid <= %d and max_cid >= %d", $user->uid, $cid, $cid); + if (db_fetch_object($result)) { + return false; + } + + return true; +} + +function comment_num_new($nid) { + global $user; + + if (! $user->uid) { + return 0; + } + + $result = db_result(db_query("SELECT COUNT(c.cid) FROM {comments} c INNER JOIN {comments_history} h ON h.uid = %d AND c.cid >= h.min_cid AND c.cid <= h.max_cid WHERE c.nid = %d AND c.status = 0", $user->uid, $nid)); + + $all = comment_num_all($nid); + return $all - $result; +} + +function comment_cron() { + $rows = db_query("SELECT * FROM {comments_history} ORDER BY uid, min_cid"); + + if (! ($row = db_fetch_object($rows))) { + return; + } + + $uid = $row->uid; + $min = $row->min_cid; + $max = $row->max_cid; + $updating = false; + + while ($row = db_fetch_object($rows)) { + if ($row->uid == $uid && $row->min_cid <= $max + 1) { + $updating = true; + $max = max($max, $row->max_cid); + continue; + } + if ($updating) { + $updates[] = array($uid, $min, $max); + } + $uid = $row->uid; + $min = $row->min_cid; + $max = $row->max_cid; + $updating = false; + } + + if ($updating) { + $updates[] = array($uid, $min, $max); + } + + if (! $updates) { + return; + } + + foreach ($updates as $update) { + $uid = $update[0]; + $min = $update[1]; + $max = $update[2]; + + db_query("INSERT INTO {comments_history} (uid, min_cid, max_cid) values (%d, %d, %d)", $uid, $min, $max); + db_query("DELETE FROM {comments_history} WHERE uid = %d AND (min_cid > %d and max_cid < %d) OR (min_cid = %d and max_cid < %d) OR (min_cid > %d AND max_cid = %d)", $uid, $min, $max, $min, $max, $min, $max); + } +} + ?> --- ./modules/forum.module 2004/03/01 14:51:29 1.3 +++ ./modules/forum.module 2004/03/11 04:02:06 @@ -370,7 +370,7 @@ $topic->new = 1; } else { - $comments = db_result(db_query("SELECT COUNT(c.nid) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = '$topic->nid' AND n.status = 1 AND c.status = 0 AND timestamp > '$history' GROUP BY n.nid")); + $comments = comment_num_new($topic->nid); $topic->new_replies = $comments ? $comments : 0; if ($topic->new_replies) { --- ./modules/tracker.module 2004/03/11 04:10:55 1.1 +++ ./modules/tracker.module 2004/03/11 04:11:00 @@ -66,7 +66,7 @@ $comments = array(); while ($comment = db_fetch_object($cresult)) { - $comments[] = "
  • ". t("%subject by %author", array("%subject" => l($comment->subject, "node/view/$node->nid#$comment->cid"), "%author" => format_name($comment))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("theme_mark") : "") ."
  • \n"; + $comments[] = "
  • ". t("%subject by %author", array("%subject" => l($comment->subject, "node/view/$node->nid#$comment->cid"), "%author" => format_name($comment))) ." ". (comment_is_new($comment->cid) ? theme("theme_mark") : "") ."
  • \n"; } if ($comments) {