implement catchup with selectable updated criteria

This commit is contained in:
Andrew Dolgov 2013-03-31 12:37:42 +04:00
parent bf1fee8347
commit c8b693cf7f
4 changed files with 117 additions and 69 deletions

View file

@ -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"));
}

View file

@ -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");
}
}

View file

@ -194,9 +194,15 @@
onclick="viewCurrentFeed()">
<?php echo __('Update') ?></button>
<button dojoType="dijit.form.Button"
onclick="catchupCurrentFeed()">
<?php echo __('Mark as read') ?></button>
<select title="<?php echo __('Mark feed as read') ?>"
onchange="catchupCurrentFeed(this)"
dojoType="dijit.form.Select" name="catchup_feed">
<option selected="selected" value="default"><?php echo __('Mark as read') ?></option>
<option value="all"><?php echo __('All articles') ?></option>
<option value="1day"><?php echo __('Older than one day') ?></option>
<option value="1week"><?php echo __('Older than one week') ?></option>
<option value="2weeks"><?php echo __('Older than two weeks') ?></option>
</select>
</form>

View file

@ -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("");