Established a function to get the first unread comment for a given user and node

(DBOINCP-167)
This commit is contained in:
Tristan Olive 2015-06-12 14:06:40 -04:00
parent 8e33b034a0
commit db181f42b5
2 changed files with 24 additions and 16 deletions

View File

@ -94,6 +94,28 @@ function boincuser_check_credit_requirements() {
}
}
/**
* Get the cid of the first comment the user has not seen on a given node
*/
function boincuser_get_first_unread_comment_id($nid, $uid = NULL) {
if (!$uid) {
global $user;
$uid = $user->uid;
}
return db_result(db_query("
SELECT c.cid
FROM {node} n
INNER JOIN {comments} c ON c.nid = n.nid
LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d
WHERE n.nid = %d
AND n.status = 1
AND c.timestamp > h.timestamp
ORDER BY c.timestamp ASC
LIMIT 1",
$uid, $nid
));
}
/**
* Determine the first unique name from a given base
*/

View File

@ -472,24 +472,10 @@ function boinc_preprocess_comment(&$vars, $hook) {
*/
function boinc_preprocess_forum_topic_list(&$variables) {
if (!empty($variables['topics'])) {
global $user;
foreach ($variables['topics'] as $id => $topic) {
if ($topic->new_replies) {
$cid = db_result(db_query("
SELECT c.cid
FROM {node} n
INNER JOIN {comments} c ON c.nid = n.nid
LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d
WHERE n.nid = %d
AND n.status = 1
AND c.timestamp > h.timestamp
ORDER BY c.timestamp ASC
LIMIT 1",
$user->uid, $topic->nid
));
if ($cid) {
$variables['topics'][$id]->new_url = url("goto/comment/{$cid}");
}
$cid = boincuser_get_first_unread_comment_id($topic->nid);
$variables['topics'][$id]->new_url = url("goto/comment/{$cid}");
}
}
}