From c8b693cf7f8616e4dc37ee2f370a01b6642ac7f5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 31 Mar 2013 12:37:42 +0400 Subject: [PATCH] implement catchup with selectable updated criteria --- classes/rpc.php | 3 +- include/functions.php | 121 ++++++++++++++++++++++++------------------ index.php | 12 +++-- js/feedlist.js | 50 ++++++++++++----- 4 files changed, 117 insertions(+), 69 deletions(-) diff --git a/classes/rpc.php b/classes/rpc.php index 4ef0fe75..3a20db6f 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -593,8 +593,9 @@ class RPC extends Handler_Protected { function catchupFeed() { $feed_id = db_escape_string($this->link, $_REQUEST['feed_id']); $is_cat = db_escape_string($this->link, $_REQUEST['is_cat']) == "true"; + $mode = db_escape_string($this->link, $_REQUEST['mode']); - catchup_feed($this->link, $feed_id, $is_cat, false); + catchup_feed($this->link, $feed_id, $is_cat, false, false, $mode); print json_encode(array("message" => "UPDATE_COUNTERS")); } diff --git a/include/functions.php b/include/functions.php index 307f6620..33014e2d 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1003,12 +1003,42 @@ } } - function catchup_feed($link, $feed, $cat_view, $owner_uid = false, $max_id = false) { + function catchup_feed($link, $feed, $cat_view, $owner_uid = false, $max_id = false, $mode = 'all') { if (!$owner_uid) $owner_uid = $_SESSION['uid']; //if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { + // Todo: all this interval stuff needs some generic generator function + + $date_qpart = "false"; + + switch ($mode) { + case "1day": + if (DB_TYPE == "pgsql") { + $date_qpart = "updated < NOW() - INTERVAL '1 day' "; + } else { + $date_qpart = "updated < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; + } + break; + case "1week": + if (DB_TYPE == "pgsql") { + $date_qpart = "updated < NOW() - INTERVAL '1 week' "; + } else { + $date_qpart = "updated < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; + } + break; + case "2weeks": + if (DB_TYPE == "pgsql") { + $date_qpart = "updated < NOW() - INTERVAL '2 week' "; + } else { + $date_qpart = "updated < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; + } + break; + default: + $date_qpart = "true"; + } + if (is_numeric($feed)) { if ($cat_view) { @@ -1026,43 +1056,44 @@ } db_query($link, "UPDATE ttrss_user_entries - SET unread = false,last_read = NOW() - WHERE feed_id IN (SELECT id FROM ttrss_feeds WHERE $cat_qpart) - AND unread = true - AND owner_uid = $owner_uid"); + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND feed_id IN + (SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart) as tmp)"); } else if ($feed == -2) { db_query($link, "UPDATE ttrss_user_entries SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*) FROM ttrss_user_labels2 WHERE article_id = ref_id) > 0 - AND unread = true AND owner_uid = $owner_uid"); + AND unread = true AND $date_qpart AND owner_uid = $owner_uid"); } } else if ($feed > 0) { db_query($link, "UPDATE ttrss_user_entries - SET unread = false,last_read = NOW() - WHERE feed_id = '$feed' - AND unread = true - AND owner_uid = $owner_uid"); + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND feed_id = $feed AND $date_qpart) as tmp)"); } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred if ($feed == -1) { db_query($link, "UPDATE ttrss_user_entries - SET unread = false,last_read = NOW() - WHERE marked = true - AND unread = true - AND owner_uid = $owner_uid"); + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND marked = true AND $date_qpart) as tmp)"); } if ($feed == -2) { db_query($link, "UPDATE ttrss_user_entries - SET unread = false,last_read = NOW() - WHERE published = true - AND unread = true - AND owner_uid = $owner_uid"); + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND published = true AND $date_qpart) as tmp)"); } if ($feed == -3) { @@ -1076,56 +1107,44 @@ INTERVAL $intl HOUR) "; } - $result = db_query($link, "SELECT id FROM ttrss_entries, - ttrss_user_entries WHERE $match_part AND - unread = true AND - ttrss_user_entries.ref_id = ttrss_entries.id AND - owner_uid = $owner_uid"); - - $affected_ids = array(); - - while ($line = db_fetch_assoc($result)) { - array_push($affected_ids, $line["id"]); - } - - catchupArticlesById($link, $affected_ids, 0); + db_query($link, "UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND feed_id = $feed AND $date_qpart AND $match_part) as tmp)"); } if ($feed == -4) { db_query($link, "UPDATE ttrss_user_entries - SET unread = false,last_read = NOW() - WHERE unread = true AND - owner_uid = $owner_uid"); + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id + AND owner_uid = $owner_uid AND unread = true AND $date_qpart) as tmp)"); } } else if ($feed < LABEL_BASE_INDEX) { // label $label_id = feed_to_label_id($feed); - db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2 - SET unread = false, last_read = NOW() - WHERE label_id = '$label_id' AND unread = true - AND owner_uid = '$owner_uid' AND ref_id = article_id"); + db_query($link, "UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_user_labels2 WHERE ref_id = id + AND label_id = '$label_id' AND ref_id = article_id + AND owner_uid = $owner_uid AND unread = true AND $date_qpart) as tmp)"); } ccache_update($link, $feed, $owner_uid, $cat_view); } else { // tag - db_query($link, "BEGIN"); + db_query($link, "UPDATE ttrss_user_entries + SET unread = false, last_read = NOW() WHERE ref_id IN + (SELECT id FROM + (SELECT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id + AND post_int_id = int_id AND tag_name = '$feed' + AND ttrss_user_entries.owner_uid = $owner_uid AND unread = true AND $date_qpart) as tmp)"); - $tag_name = db_escape_string($link, $feed); - - $result = db_query($link, "SELECT post_int_id FROM ttrss_tags - WHERE tag_name = '$tag_name' AND owner_uid = $owner_uid"); - - while ($line = db_fetch_assoc($result)) { - db_query($link, "UPDATE ttrss_user_entries SET - unread = false, last_read = NOW() - WHERE unread = true - AND int_id = " . $line["post_int_id"]); - } - db_query($link, "COMMIT"); } } diff --git a/index.php b/index.php index f7962197..d9363644 100644 --- a/index.php +++ b/index.php @@ -194,9 +194,15 @@ onclick="viewCurrentFeed()"> - + diff --git a/js/feedlist.js b/js/feedlist.js index 28fadc0b..9d643142 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -380,8 +380,20 @@ function getNextUnreadFeed(feed, is_cat) { } } -function catchupCurrentFeed() { - return catchupFeed(getActiveFeedId(), activeFeedIsCat()); +function catchupCurrentFeed(elem) { + + if (elem) { + var toolbar = document.forms["main_toolbar_form"]; + var catchup_feed = dijit.getEnclosingWidget(toolbar.catchup_feed); + var mode = catchup_feed.attr('value'); + + if (mode != 'default') { + catchupFeed(getActiveFeedId(), activeFeedIsCat(), mode); + catchup_feed.attr('value', 'default'); + } + } else { + catchupFeed(getActiveFeedId(), activeFeedIsCat()); + } } function catchupFeedInGroup(id) { @@ -400,11 +412,26 @@ function catchupFeedInGroup(id) { } } -function catchupFeed(feed, is_cat) { +function catchupFeed(feed, is_cat, mode) { try { if (is_cat == undefined) is_cat = false; - var str = __("Mark all articles in %s as read?"); + var str = false; + + switch (mode) { + case "1day": + str = __("Mark all articles in %s older than 1 day as read?"); + break; + case "1week": + str = __("Mark all articles in %s older than 1 week as read?"); + break; + case "2weeks": + str = __("Mark all articles in %s older than 2 weeks as read?"); + break; + default: + str = __("Mark all articles in %s as read?"); + } + var fn = getFeedName(feed, is_cat); str = str.replace("%s", fn); @@ -414,7 +441,7 @@ function catchupFeed(feed, is_cat) { } var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + - feed + "&is_cat=" + is_cat; + feed + "&is_cat=" + is_cat + "&mode=" + mode; console.log(catchup_query); @@ -425,15 +452,6 @@ function catchupFeed(feed, is_cat) { onComplete: function(transport) { handle_rpc_json(transport); - if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { - - $$("#headlines-frame > div[id*=RROW][class*=Unread]").each( - function(child) { - child.removeClassName("Unread"); - } - ); - } - var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; if (show_next_feed) { @@ -442,6 +460,10 @@ function catchupFeed(feed, is_cat) { if (nuf) { viewfeed(nuf, '', is_cat); } + } else { + if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { + viewCurrentFeed(); + } } notify(""); -- 2.39.5