Commit a54a4c4f authored by greggles's avatar greggles

feature #186025 by aclight, greggles: Distinguish between new comments and comment edits

parent 7d11f692
......@@ -57,6 +57,12 @@ function comment_notify_schema() {
'length' => '32',
'not null' => TRUE,
'default' => ''),
'notified' => array(
'type' => 'int',
'description' => 'A boolean indicator for whether or not a notification for the comment has been sent: 1 means yes, 0 means no.',
'size' => 'tiny',
'not null' => TRUE,
'disp-width' => '11'),
),
'primary key' => array('cid'),
'indexes' => array(
......@@ -251,5 +257,21 @@ function comment_notify_update_6003() {
$ret['#finished'] = $_SESSION['comment_notify_update_6003'] / $_SESSION['comment_notify_update_6003_max'];
}
return $ret;
}
/**
* Add a "notified" column to {comment_notify} to keep track of whether
* notifications have already been sent out for a given comment. This
* prevents new notifications from being sent when a comment is edited.
*/
function comment_notify_update_6004() {
$ret = array();
db_add_field($ret, 'comment_notify', 'notified', array('type' => 'int', 'size' => 'small', 'unsigned' => TRUE, 'not null' => TRUE));
// Set the value in the notified column to 1 for all existing records.
$ret[] = update_sql('UPDATE {comment_notify} SET notified = 1');
return $ret;
}
\ No newline at end of file
......@@ -352,6 +352,16 @@ function _comment_notify_mailalert($comment) {
global $base_url;
global $user;
$nid = $comment->nid;
$cid = $comment->cid;
// Check to see if a notification has already been sent for this
// comment so that edits to a comment don't trigger an additional
// notification.
if (db_result(db_query('SELECT cid from {comment_notify} WHERE cid = %d AND notified = %d', $cid, 1))) {
return;
}
$initial_language = $language;
if (function_exists('locale')) {
......@@ -359,8 +369,6 @@ function _comment_notify_mailalert($comment) {
$languages = $languages['name'];
}
$nid = $comment->nid;
$cid = $comment->cid;
$node = node_load($nid);
if (!isset($comment->mail)) {
$comment_account = user_load(array('name' => $comment->name));
......@@ -413,9 +421,8 @@ function _comment_notify_mailalert($comment) {
$mail = empty($alert->cmail) ? $umail : $alert->cmail;
if ($alert->notify == COMMENT_NOTIFY_COMMENT && $alert->cid != $comment->pid) {
break;
continue;
}
if ($mail != $comment_mail && !in_array($mail, $sent_to) && $alert->uid != $comment->uid) {
$message = array();
if (!empty($alert->uid)) {
......@@ -474,6 +481,9 @@ function _comment_notify_mailalert($comment) {
$language = $initial_language;
}
}
// Record that a notification was sent for this comment so that
// notifications aren't sent again if the comment is later edited.
db_query('UPDATE {comment_notify} SET notified = 1 WHERE cid = %d', $cid);
}
function comment_notify_mail($key, &$message, $params) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment