diff --git a/backend.php b/backend.php
index abc0988ad..dafb0b95b 100644
--- a/backend.php
+++ b/backend.php
@@ -241,9 +241,17 @@
// }
if (get_pref($link, 'ENABLE_FEED_CATS')) {
- $order_by_qpart = "category,title";
+ if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
+ $order_by_qpart = "category,unread DESC,title";
+ } else {
+ $order_by_qpart = "category,title";
+ }
} else {
- $order_by_qpart = "title";
+ if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
+ $order_by_qpart = "unread DESC,title";
+ } else {
+ $order_by_qpart = "title";
+ }
}
$result = db_query($link, "SELECT ttrss_feeds.*,
diff --git a/functions.js b/functions.js
index 3b6339b82..7ed20d532 100644
--- a/functions.js
+++ b/functions.js
@@ -581,6 +581,10 @@ function all_counters_callback() {
if (runtime) {
getMainContext().parse_runtime_info(runtime);
}
+
+ if (getInitParam("feeds_sort_by_unread")) {
+ resort_feedlist();
+ }
} catch (e) {
exception_error("all_counters_callback", e);
@@ -588,6 +592,75 @@ function all_counters_callback() {
}
}
+function get_feed_entry_unread(doc, elem) {
+
+ var id = elem.id.replace("FEEDR-", "");
+
+ if (id <= 0) {
+ return -1;
+ }
+
+ try {
+ return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
+ } catch (e) {
+ return -1;
+ }
+}
+
+function resort_category(doc, node) {
+ debug("resort_category: " + node);
+
+ if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
+ for (i = 0; i < node.childNodes.length; i++) {
+ if (node.childNodes[i].nodeName != "LI") { continue; }
+
+ if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
+ continue;
+ }
+
+ for (j = i+1; j < node.childNodes.length; j++) {
+ if (node.childNodes[j].nodeName != "LI") { continue; }
+
+ var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
+ var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
+
+ if (cur_val > tmp_val) {
+ tempnode_i = node.childNodes[i].cloneNode(true);
+ tempnode_j = node.childNodes[j].cloneNode(true);
+ node.replaceChild(tempnode_i, node.childNodes[j]);
+ node.replaceChild(tempnode_j, node.childNodes[i]);
+ }
+ }
+
+ }
+ }
+
+}
+
+function resort_feedlist() {
+ debug("resort_feedlist");
+
+ var fd = getFeedsContext().document;
+
+ if (fd.getElementById("feedCatHolder")) {
+
+ var feeds = fd.getElementById("feedList");
+ var child = feeds.firstChild;
+
+ while (child) {
+
+ if (child.id == "feedCatHolder") {
+ resort_category(fd, child.firstChild);
+ }
+
+ child = child.nextSibling;
+ }
+
+ } else {
+ resort_category(fd, fd.getElementById("feedList"));
+ }
+}
+
function update_all_counters(feed) {
if (xmlhttp_ready(xmlhttp_rpc)) {
var query = "backend.php?op=rpc&subop=getAllCounters";
@@ -1147,7 +1220,7 @@ function debug(msg) {
var c = ctx.document.getElementById('debug_output');
if (c && c.style.display == "block") {
- while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
+ while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
c.removeChild(c.lastChild);
}
diff --git a/functions.php b/functions.php
index 3d6078b14..6bcebe598 100644
--- a/functions.php
+++ b/functions.php
@@ -1718,6 +1718,9 @@
print "";
+ print "";
+
print "";
}
diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql
index e1d61009c..1e51df31c 100644
--- a/schema/ttrss_schema_mysql.sql
+++ b/schema/ttrss_schema_mysql.sql
@@ -247,6 +247,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
+
create table ttrss_user_prefs (
owner_uid integer not null,
pref_name varchar(250),
diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index 1726ecc8e..042e650fd 100644
--- a/schema/ttrss_schema_pgsql.sql
+++ b/schema/ttrss_schema_pgsql.sql
@@ -227,6 +227,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
+
create table ttrss_user_prefs (
owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE,
diff --git a/schema/upgrade-1.1.5-1.1.7-mysql.sql b/schema/upgrade-1.1.5-1.1.7-mysql.sql
index bfccc3358..a7fb99024 100644
--- a/schema/upgrade-1.1.5-1.1.7-mysql.sql
+++ b/schema/upgrade-1.1.5-1.1.7-mysql.sql
@@ -3,6 +3,8 @@ insert into ttrss_themes (theme_name, theme_path) values ('Old-skool', 'compat')
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
+
insert into ttrss_filter_actions (id,name,description) values (3, 'mark',
'Set starred');
diff --git a/schema/upgrade-1.1.5-1.1.7-pgsql.sql b/schema/upgrade-1.1.5-1.1.7-pgsql.sql
index 4a2237a3f..4c7c78f9d 100644
--- a/schema/upgrade-1.1.5-1.1.7-pgsql.sql
+++ b/schema/upgrade-1.1.5-1.1.7-pgsql.sql
@@ -5,6 +5,8 @@ insert into ttrss_themes (theme_name, theme_path) values ('Old-skool', 'compat')
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
+
insert into ttrss_filter_actions (id,name,description) values (3, 'mark',
'Set starred');