Console: Limit age of news entries displayed

This commit is contained in:
zzz
2016-12-22 12:03:28 +00:00
parent 0819857b86
commit e625e67b5d
3 changed files with 17 additions and 7 deletions

View File

@ -20,7 +20,7 @@ import net.i2p.util.SystemVersion;
*/
public class NewsFeedHelper extends HelperBase {
private int _start = 0;
private int _start;
private int _limit = 2;
/**
@ -35,14 +35,15 @@ public class NewsFeedHelper extends HelperBase {
}
public String getEntries() {
return getEntries(_context, _start, _limit);
return getEntries(_context, _start, _limit, 0);
}
/**
* @param max less than or equal to zero means all
* @param ageLimit time before now, less than or equal to zero means all (after the first)
* @return non-null, "" if none
*/
static String getEntries(I2PAppContext ctx, int start, int max) {
static String getEntries(I2PAppContext ctx, int start, int max, long ageLimit) {
if (max <= 0)
max = Integer.MAX_VALUE;
StringBuilder buf = new StringBuilder(512);
@ -69,8 +70,11 @@ public class NewsFeedHelper extends HelperBase {
fmt.setTimeZone(SystemVersion.getSystemTimeZone(ctx));
int i = 0;
for (NewsEntry entry : entries) {
if (i++ < start)
if (i < start)
continue;
if (i > start && entry.updated > 0 && ageLimit > 0 &&
entry.updated < ctx.clock().now() - ageLimit)
break;
buf.append("<div class=\"newsentry\"><h3>");
if (entry.updated > 0) {
Date date = new Date(entry.updated);
@ -91,7 +95,7 @@ public class NewsFeedHelper extends HelperBase {
buf.append("</h3>\n<div class=\"newscontent\">\n")
.append(entry.content)
.append("\n</div></div>\n");
if (i >= start + max)
if (++i >= start + max)
break;
}
}

View File

@ -231,7 +231,8 @@ public class NewsHelper extends ContentHelper {
*/
@Override
public String getContent() {
return NewsFeedHelper.getEntries(_context, 0, 2);
// show a min of 1, max of 3, none older than 60 days over min
return NewsFeedHelper.getEntries(_context, 0, 3, 60*24*60*60*1000L);
}
/**

View File

@ -637,8 +637,13 @@ class SummaryBarRenderer {
// the router sets the JVM time zone to UTC but saves the original here so we can get it
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
int i = 0;
final int max = 2;
// show a min of 1, max of 3, none older than 60 days over min
final int min = 1;
final int max = 3;
for (NewsEntry entry : entries) {
if (i >= min && entry.updated > 0 &&
entry.updated < _context.clock().now() - 60*24*60*60*1000L)
break;
buf.append("<li><a href=\"/?news=1&amp;consoleNonce=")
.append(consoleNonce)
.append("\">");