forked from I2P_Developers/i2p.i2p
Console: Hide news section in summary bar if news fetching
is disabled, or if empty (ticket #2301)
This commit is contained in:
@ -16,6 +16,7 @@ import net.i2p.data.DataHelper;
|
|||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.news.NewsEntry;
|
import net.i2p.router.news.NewsEntry;
|
||||||
import net.i2p.router.news.NewsManager;
|
import net.i2p.router.news.NewsManager;
|
||||||
|
import net.i2p.router.web.ConfigUpdateHandler;
|
||||||
import net.i2p.router.web.CSSHelper;
|
import net.i2p.router.web.CSSHelper;
|
||||||
import net.i2p.router.web.Messages;
|
import net.i2p.router.web.Messages;
|
||||||
import net.i2p.router.web.NavHelper;
|
import net.i2p.router.web.NavHelper;
|
||||||
@ -974,11 +975,6 @@ class SummaryBarRenderer {
|
|||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
String consoleNonce = CSSHelper.getNonce();
|
String consoleNonce = CSSHelper.getNonce();
|
||||||
if (consoleNonce != null) {
|
if (consoleNonce != null) {
|
||||||
// Set up title and pre-headings stuff.
|
|
||||||
//buf.append("<h3><a href=\"/configupdate\">")
|
|
||||||
buf.append("<h3><a href=\"/news\">")
|
|
||||||
.append(_t("News & Updates"))
|
|
||||||
.append("</a></h3><hr class=\"b\"><div class=\"sb_newsheadings\">\n");
|
|
||||||
// Get news content.
|
// Get news content.
|
||||||
List<NewsEntry> entries = Collections.emptyList();
|
List<NewsEntry> entries = Collections.emptyList();
|
||||||
ClientAppManager cmgr = _context.clientAppManager();
|
ClientAppManager cmgr = _context.clientAppManager();
|
||||||
@ -988,18 +984,33 @@ class SummaryBarRenderer {
|
|||||||
entries = nmgr.getEntries();
|
entries = nmgr.getEntries();
|
||||||
}
|
}
|
||||||
if (!entries.isEmpty()) {
|
if (!entries.isEmpty()) {
|
||||||
buf.append("<table>\n");
|
|
||||||
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||||
int i = 0;
|
int i = 0;
|
||||||
// show a min of 1, max of 3, none older than 60 days over min
|
// show a min of 1, max of 3, none older than 60 days over min
|
||||||
final int min = 1;
|
// Except, if news fetching is disabled, min is 0 and oldest is 7 days.
|
||||||
|
// We still show news even if disabled, because the user could click it manually
|
||||||
|
String freq = _context.getProperty(ConfigUpdateHandler.PROP_REFRESH_FREQUENCY,
|
||||||
|
ConfigUpdateHandler.DEFAULT_REFRESH_FREQUENCY);
|
||||||
|
long ms = ConfigUpdateHandler.DEFAULT_REFRESH_FREQ;
|
||||||
|
try {
|
||||||
|
ms = Long.parseLong(freq);
|
||||||
|
} catch (NumberFormatException nfe) {}
|
||||||
|
final int min = (ms > 0) ? 1 : 0;
|
||||||
final int max = 3;
|
final int max = 3;
|
||||||
|
final long age = (ms > 0) ? 60*24*60*60*1000L : 7*24*60*60*1000L;
|
||||||
|
final long oldest = _context.clock().now() - age;
|
||||||
for (NewsEntry entry : entries) {
|
for (NewsEntry entry : entries) {
|
||||||
if (i >= min && entry.updated > 0 &&
|
if (i >= min && entry.updated > 0 &&
|
||||||
entry.updated < _context.clock().now() - 60*24*60*60*1000L)
|
entry.updated < oldest)
|
||||||
break;
|
break;
|
||||||
|
if (i == 0) {
|
||||||
|
// Set up title and pre-headings stuff.
|
||||||
|
buf.append("<h3><a href=\"/news\">")
|
||||||
|
.append(_t("News & Updates"))
|
||||||
|
.append("</a></h3><hr class=\"b\"><div class=\"sb_newsheadings\">\n<table>\n");
|
||||||
|
}
|
||||||
buf.append("<tr><td><a href=\"/?news=1&consoleNonce=")
|
buf.append("<tr><td><a href=\"/?news=1&consoleNonce=")
|
||||||
.append(consoleNonce)
|
.append(consoleNonce)
|
||||||
.append("\"");
|
.append("\"");
|
||||||
@ -1014,17 +1025,9 @@ class SummaryBarRenderer {
|
|||||||
if (++i >= max)
|
if (++i >= max)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf.append("</table>\n");
|
if (i > 0)
|
||||||
} else {
|
buf.append("</table>\n</div>\n");
|
||||||
buf.append("<center><i>")
|
|
||||||
.append(_t("none"))
|
|
||||||
.append("</i></center>");
|
|
||||||
}
|
}
|
||||||
// Add post-headings stuff.
|
|
||||||
//buf.append("<a href=\"/news\">")
|
|
||||||
//.append(_t("Show all news"))
|
|
||||||
//.append("</a>\n");
|
|
||||||
buf.append("</div>\n");
|
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user