--- subscriptions.module.orig 2008-04-11 11:19:55.000000000 -0600 +++ subscriptions.module 2008-04-11 11:48:30.000000000 -0600 @@ -210,6 +210,50 @@ function subscriptions_queue($event) { $event['load_args'] = serialize($event['load_args']); } + // !custom ----- + // get the uids of all the subscribers to this node + $sub_result = db_query(" + SELECT recipient_uid FROM {subscriptions} + WHERE field = %d AND value = %d", 'nid', $event['node']->nid); + + if ($event['load_function'] == 'subscriptions_content_comment_load') { + $max_comments = 1; + if ($event['action'] == 'update') { + $nosend = true; // don't send notifications on comment updates + } + } elseif ($event['load_function'] == 'subscriptions_content_node_load') { + if ($event['action'] == 'update') { + $max_comments = 0; + // if there's a new comment and a node update - no send + // if there's no new comment and a node update - send + // need to check whether the node update is updating a previously new node + } + } + + $nosend_uids = array(); + // for each subscriber: check if new comments > 1, and if so add to no-send list + while ($row = db_fetch_object($sub_result)) { + // get the time for subscriber's last read of this node + $history = db_fetch_object(db_query(" + SELECT timestamp FROM {history} + WHERE uid = %d AND nid = %d", $row->recipient_uid, $event['node']->nid)); + $last_read = $history->timestamp ? $history->timestamp : 0; + + // count comments since last read time + $new_comments = (int)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', + $event['node']->nid, $last_read)); + + // if more than one unread comment, add to no-send list + if ($new_comments > $max_comments || $nosend == true) { + array_push($nosend_uids, $row->recipient_uid); + } + } + $nosend_list = implode(',', $nosend_uids); + // end custom ----- + foreach (module_implements('subscriptions') as $subs_module) { $subs_module_query = module_invoke($subs_module, 'subscriptions', 'queue', $event); if (!isset($subs_module_query)) { @@ -231,6 +275,12 @@ function subscriptions_queue($event) { $where[] = "s.recipient_uid != %d"; $args[] = $user->uid; } + // !custom + if ($nosend_list) { + $where[] = "s.recipient_uid NOT IN (%s)"; + $args[] = $nosend_list; + } + // end custom $conditions = implode(' AND ', $where); $sql = " INSERT INTO {subscriptions_queue} (uid, name, mail, language, module, field, value, author_uid, send_interval, digest, last_sent, load_function, load_args, is_new)