implement catchup with selectable updated criteria
This commit is contained in:
parent
bf1fee8347
commit
c8b693cf7f
4 changed files with 117 additions and 69 deletions
|
@ -593,8 +593,9 @@ class RPC extends Handler_Protected {
|
||||||
function catchupFeed() {
|
function catchupFeed() {
|
||||||
$feed_id = db_escape_string($this->link, $_REQUEST['feed_id']);
|
$feed_id = db_escape_string($this->link, $_REQUEST['feed_id']);
|
||||||
$is_cat = db_escape_string($this->link, $_REQUEST['is_cat']) == "true";
|
$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"));
|
print json_encode(array("message" => "UPDATE_COUNTERS"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 (!$owner_uid) $owner_uid = $_SESSION['uid'];
|
||||||
|
|
||||||
//if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
|
//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 (is_numeric($feed)) {
|
||||||
if ($cat_view) {
|
if ($cat_view) {
|
||||||
|
|
||||||
|
@ -1026,43 +1056,44 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
db_query($link, "UPDATE ttrss_user_entries
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
SET unread = false,last_read = NOW()
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
WHERE feed_id IN (SELECT id FROM ttrss_feeds WHERE $cat_qpart)
|
(SELECT id FROM
|
||||||
AND unread = true
|
(SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
|
||||||
AND owner_uid = $owner_uid");
|
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) {
|
} else if ($feed == -2) {
|
||||||
|
|
||||||
db_query($link, "UPDATE ttrss_user_entries
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
|
SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
|
||||||
FROM ttrss_user_labels2 WHERE article_id = ref_id) > 0
|
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) {
|
} else if ($feed > 0) {
|
||||||
|
|
||||||
db_query($link, "UPDATE ttrss_user_entries
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
SET unread = false,last_read = NOW()
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
WHERE feed_id = '$feed'
|
(SELECT id FROM
|
||||||
AND unread = true
|
(SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
|
||||||
AND owner_uid = $owner_uid");
|
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
|
} else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred
|
||||||
|
|
||||||
if ($feed == -1) {
|
if ($feed == -1) {
|
||||||
db_query($link, "UPDATE ttrss_user_entries
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
SET unread = false,last_read = NOW()
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
WHERE marked = true
|
(SELECT id FROM
|
||||||
AND unread = true
|
(SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
|
||||||
AND owner_uid = $owner_uid");
|
AND owner_uid = $owner_uid AND unread = true AND marked = true AND $date_qpart) as tmp)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($feed == -2) {
|
if ($feed == -2) {
|
||||||
db_query($link, "UPDATE ttrss_user_entries
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
SET unread = false,last_read = NOW()
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
WHERE published = true
|
(SELECT id FROM
|
||||||
AND unread = true
|
(SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
|
||||||
AND owner_uid = $owner_uid");
|
AND owner_uid = $owner_uid AND unread = true AND published = true AND $date_qpart) as tmp)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($feed == -3) {
|
if ($feed == -3) {
|
||||||
|
@ -1076,56 +1107,44 @@
|
||||||
INTERVAL $intl HOUR) ";
|
INTERVAL $intl HOUR) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = db_query($link, "SELECT id FROM ttrss_entries,
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
ttrss_user_entries WHERE $match_part AND
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
unread = true AND
|
(SELECT id FROM
|
||||||
ttrss_user_entries.ref_id = ttrss_entries.id AND
|
(SELECT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
|
||||||
owner_uid = $owner_uid");
|
AND owner_uid = $owner_uid AND unread = true AND feed_id = $feed AND $date_qpart AND $match_part) as tmp)");
|
||||||
|
|
||||||
$affected_ids = array();
|
|
||||||
|
|
||||||
while ($line = db_fetch_assoc($result)) {
|
|
||||||
array_push($affected_ids, $line["id"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
catchupArticlesById($link, $affected_ids, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($feed == -4) {
|
if ($feed == -4) {
|
||||||
db_query($link, "UPDATE ttrss_user_entries
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
SET unread = false,last_read = NOW()
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
WHERE unread = true AND
|
(SELECT id FROM
|
||||||
owner_uid = $owner_uid");
|
(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
|
} else if ($feed < LABEL_BASE_INDEX) { // label
|
||||||
|
|
||||||
$label_id = feed_to_label_id($feed);
|
$label_id = feed_to_label_id($feed);
|
||||||
|
|
||||||
db_query($link, "UPDATE ttrss_user_entries, ttrss_user_labels2
|
db_query($link, "UPDATE ttrss_user_entries
|
||||||
SET unread = false, last_read = NOW()
|
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||||
WHERE label_id = '$label_id' AND unread = true
|
(SELECT id FROM
|
||||||
AND owner_uid = '$owner_uid' AND ref_id = article_id");
|
(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);
|
ccache_update($link, $feed, $owner_uid, $cat_view);
|
||||||
|
|
||||||
} else { // tag
|
} 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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
index.php
12
index.php
|
@ -194,9 +194,15 @@
|
||||||
onclick="viewCurrentFeed()">
|
onclick="viewCurrentFeed()">
|
||||||
<?php echo __('Update') ?></button>
|
<?php echo __('Update') ?></button>
|
||||||
|
|
||||||
<button dojoType="dijit.form.Button"
|
<select title="<?php echo __('Mark feed as read') ?>"
|
||||||
onclick="catchupCurrentFeed()">
|
onchange="catchupCurrentFeed(this)"
|
||||||
<?php echo __('Mark as read') ?></button>
|
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>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -380,8 +380,20 @@ function getNextUnreadFeed(feed, is_cat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function catchupCurrentFeed() {
|
function catchupCurrentFeed(elem) {
|
||||||
return catchupFeed(getActiveFeedId(), activeFeedIsCat());
|
|
||||||
|
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) {
|
function catchupFeedInGroup(id) {
|
||||||
|
@ -400,11 +412,26 @@ function catchupFeedInGroup(id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function catchupFeed(feed, is_cat) {
|
function catchupFeed(feed, is_cat, mode) {
|
||||||
try {
|
try {
|
||||||
if (is_cat == undefined) is_cat = false;
|
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);
|
var fn = getFeedName(feed, is_cat);
|
||||||
|
|
||||||
str = str.replace("%s", fn);
|
str = str.replace("%s", fn);
|
||||||
|
@ -414,7 +441,7 @@ function catchupFeed(feed, is_cat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" +
|
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);
|
console.log(catchup_query);
|
||||||
|
|
||||||
|
@ -425,15 +452,6 @@ function catchupFeed(feed, is_cat) {
|
||||||
onComplete: function(transport) {
|
onComplete: function(transport) {
|
||||||
handle_rpc_json(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";
|
var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
|
||||||
|
|
||||||
if (show_next_feed) {
|
if (show_next_feed) {
|
||||||
|
@ -442,6 +460,10 @@ function catchupFeed(feed, is_cat) {
|
||||||
if (nuf) {
|
if (nuf) {
|
||||||
viewfeed(nuf, '', is_cat);
|
viewfeed(nuf, '', is_cat);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) {
|
||||||
|
viewCurrentFeed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notify("");
|
notify("");
|
||||||
|
|
Loading…
Reference in a new issue