diff --git a/comment_notify.inc b/comment_notify.inc index 123d788..f1bd5eb 100644 --- a/comment_notify.inc +++ b/comment_notify.inc @@ -171,35 +171,6 @@ function comment_notify_update_notification($cid, $notify) { } /** - * Returns TRUE if the owner of this comment notification has already been notified. - * - * @param integer $cid - * @return boolean - */ -function comment_notify_is_notification_already_sent($cid) { - return (bool) db_select('comment_notify', 'cn') - ->fields('cn', array('cid')) - ->condition('cid', $cid) - ->condition('notified', 1) - ->execute() - ->fetchField(); -} - -/** - * Get the unique identification hash for a comment notification record. - * - * @param integer $cid - * @return string - */ -function comment_notify_get_notify_hash($cid) { - return db_select('comment_notify', 'cn') - ->fields('cn', array('notify_hash')) - ->condition('cid', $cid) - ->execute() - ->fetchField(); -} - -/** * Get the type of notification for a comment notification record. * * @param integer $cid @@ -214,21 +185,6 @@ function comment_notify_get_notification_type($cid) { } /** - * Returns the thread which a comment belongs to. - * - * @param integer $cid - * @return string - * The thread identifier. - */ -function comment_notify_get_thread($cid) { - return db_select('comment', 'c') - ->fields('c', array('thread')) - ->condition('cid', $cid) - ->execute() - ->fetchField(); -} - -/** * Get a list of mails which need to be contacted for a node. * * @param integer $nid @@ -253,7 +209,12 @@ function comment_notify_get_watchers($nid) { $query->addField('u', 'init', 'uinit'); $query->addField('u', 'mail', 'umail'); - return $query->execute(); + $cids = db_query("SELECT c.cid FROM {comment} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = :nid AND c.status = :status AND cn.notify <> :notify AND (u.uid = 0 OR u.status = 1)", array( + ':nid' => $nid, + ':status' => COMMENT_PUBLISHED, + ':notify' => COMMENT_NOTIFY_DISABLED, + ))->fetchCol(); + return comment_load_multiple($cids); } /** diff --git a/comment_notify.module b/comment_notify.module index 2df39a6..7d512a3 100644 --- a/comment_notify.module +++ b/comment_notify.module @@ -392,6 +392,18 @@ function comment_notify_user_cancel(&$edit, $account, $method) { } /** + * Implements hook_comment_load(). + */ +function comment_notify_comment_load($comments) { + $records = db_query("SELECT cid, notify, notify_hash, notified FROM {comment_notify} WHERE cid IN (:cids)", array(':cids' => array_keys($comments)))->fetchAllAssoc('cid'); + foreach ($records as $cid => $record) { + $comments[$cid]->notify = $record->notify; + $comments[$cid]->notify_hash = $record->notify_hash; + $comments[$cid]->notified = $record->notified; + } +} + +/** * Private function to send the notifications. * * @param $comment @@ -412,7 +424,7 @@ function _comment_notify_mailalert($comment) { // 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 (comment_notify_is_notification_already_sent($cid)) { + if (!empty($comment->notified)) { return; } @@ -452,7 +464,7 @@ function _comment_notify_mailalert($comment) { } // For "reply to my comments" notifications, figure out what thread this is. - $thread = comment_notify_get_thread($cid); + $thread = $comment->thread; // Get the list of commenters to notify. $watchers = comment_notify_get_watchers($nid); @@ -685,13 +697,11 @@ function comment_notify_settings_validate($form, &$form_state) { * @return * A string with the internal path to the unsubscribe link, ready to be * passed to the url() function. - * - * @see comment_notify_get_notify_hash(). */ function comment_notify_get_unsubscribe_url($comment) { module_load_include('inc', 'comment_notify', 'comment_notify'); - if ($hash = comment_notify_get_notify_hash($comment->cid)) { - return 'comment_notify/disable/' . $hash; + if (!empty($comment->notify_hash)) { + return 'comment_notify/disable/' . $comment->notify_hash; } } /** @@ -704,4 +714,4 @@ function comment_notify_field_extra_fields() { 'weight' => 4, ); return $extras; -} \ No newline at end of file +}