# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- /watcher.db.inc
+++ /watcher.db.inc
@@ -418,11 +418,19 @@
  *     An array of objects with uid as key representing users, with attributes uid, mail and name
  */
 function _watcher_db_get_users_notify_node_update($nid, $uid_exclude) {
-  $sql = "SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND notifications_updates = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 3)))";
+  $sql = "SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name, wn.added, h.timestamp 
+		FROM {watcher_nodes} wn 
+		LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid 
+		LEFT JOIN {history} h ON h.nid = wn.nid AND wn.uid = h.uid
+		LEFT JOIN {users} u ON u.uid = wus.uid 
+		WHERE wn.nid = %d AND 
+		((wn.uid <> 0 AND wn.uid <> %d AND notifications_updates = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 3)))
+		AND u.status = 1 AND wn.added < h.timestamp";
   $res = db_query($sql, $nid, $uid_exclude);
   $users = array();
   while ($row = db_fetch_object($res)) {
     $users[$row->uid] = $row;
+		db_query("UPDATE {watcher_nodes} SET added = %d WHERE uid = %d AND nid = %d", $_SERVER['REQUEST_TIME'], $row->uid, $nid);
   }
   return $users;
 }
@@ -440,11 +448,19 @@
  *     An array of objects with uid as key representing users, with attributes uid, mail and name
  */
 function _watcher_db_get_users_notify_comment_insert($nid, $uid_exclude) {
-  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND notifications_new_comments = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 2)))';
+  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name, wn.added, h.timestamp
+		FROM {watcher_nodes} wn 
+		LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid
+		INNER JOIN {history} h ON h.nid = wn.nid AND wn.uid = h.uid
+		LEFT JOIN {users} u ON u.uid = wus.uid
+		WHERE wn.nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND notifications_new_comments = 1 AND send_email = 1)
+			OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 2)))
+			AND u.status = 1 AND wn.added < h.timestamp';
   $res = db_query($sql, $nid, $uid_exclude);
   $users = array();
   while ($row = db_fetch_object($res)) {
     $users[] = $row;
+		db_query("UPDATE {watcher_nodes} SET added = %d WHERE uid = %d AND nid = %d", $_SERVER['REQUEST_TIME'], $row->uid, $nid);
   }
   return $users;
 }
@@ -462,11 +478,17 @@
  *      An array of objects with uid as key representing users, with attributes uid, mail and name
  */
 function _watcher_db_get_users_notify_about_node($nid, $uid_exclude) {
-  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {users} u ON u.uid = wn.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND send_email = 1) OR (NOT ISNULL(watch_for)))';
+  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name, wn.added, h.timestamp 
+		FROM {watcher_nodes} wn 
+		LEFT JOIN {history} h ON h.nid = wn.nid AND wn.uid = h.uid 
+		LEFT JOIN {users} u ON u.uid = wn.uid 
+		WHERE wn.nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND send_email = 1) OR (NOT ISNULL(watch_for)))
+		AND u.status = 1 AND wn.added < h.timestamp';
   $res = db_query($sql, $nid, $uid_exclude);
   $users = array();
   while ($row = db_fetch_object($res)) {
     $users[$row->uid] = $row;
+		db_query("UPDATE {watcher_nodes} SET added = %d WHERE uid = %d AND nid = %d", $_SERVER['REQUEST_TIME'], $row->uid, $nid);
   }
   return $users;
 }
