--- comment_notify.module.orig 2009-03-08 00:52:51.000000000 +0530 +++ comment_notify.module 2009-04-03 16:20:25.000000000 +0530 @@ -418,12 +418,35 @@ drupal_mail('comment_notify', 'comment_notify_mail', $author->mail, $language, $message); $sent_to[] = $author->mail; } + $thread = db_result(db_query("SELECT thread FROM {comments} WHERE cid = %d", $cid)); + //This array contains the nodeid and parent threads. + $parent_thread_ids = array(); + $parent_thread_ids[] = $nid; + $format_string = NULL; + $thread_arr = explode('.', $thread); + // $thread_arr contains the exploded thread value. + // Get values from the string thread, 3 at a time and replace the third value(.) from substring + // and then attach / at the end. keep the value in the array $parent_thread_ids[]. + // Format string is formed according to the number of thread id's. + for ($i = count($thread_arr) - 1, $j = 3; $i > 0; $i--, $j+=3) { + $thread_id = mb_substr($thread, 0, $j); + $thread_id = substr_replace($thread_id, "", -1, 1 ) ."/"; + $parent_thread_ids[] = $thread_id; + $format_string .= "'%s',"; + } - //Get the list of commenters to notify - $result = db_query("SELECT DISTINCT c.cid, c.uid, c.name, c.nid, c.mail AS cmail, u.mail AS umail, u.init AS uinit, c.uid, c.name, cn.notify, cn.notify_hash - FROM {comments} c INNER JOIN {comment_notify} cn on c.cid = cn.cid LEFT OUTER JOIN {users} u ON c.uid = u.uid - WHERE nid = %d AND cn.notify > 0 AND c.status = 0 AND (u.status = 1 OR u.uid = 0)", $nid - ); + // Replace the last comma from $format_string + $format_string = substr_replace($format_string, "", -1, 1 ); + + if (count($thread_arr) > 1) { + $conditional_expr = " AND (c.thread IN (". $format_string .") OR cn.notify = 1) "; + } + else{ + $conditional_expr = "OR cn.notify = 1"; + } + + // Get the list of commenters to notify + $result = db_query("SELECT DISTINCT c.cid, c.uid, c.name, c.nid, c.mail AS cmail, u.mail AS umail, u.init AS uinit, c.uid, c.name, cn.notify, cn.notify_hash FROM {comments} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid LEFT OUTER JOIN {users} u ON c.uid = u.uid WHERE nid = %d AND c.status = 0 AND (u.status = 1 OR u.uid = 0) ". $conditional_expr, $parent_thread_ids); // TODO? the original big query had stuff making sure the mail was populated and contained .+@.+ Perhaps check for that here and set notify = 0 if that is the case for this cid while ($alert = db_fetch_object($result)) {