forked from I2P_Developers/i2p.i2p
Console: Limit age of news entries displayed
This commit is contained in:
@ -20,7 +20,7 @@ import net.i2p.util.SystemVersion;
|
|||||||
*/
|
*/
|
||||||
public class NewsFeedHelper extends HelperBase {
|
public class NewsFeedHelper extends HelperBase {
|
||||||
|
|
||||||
private int _start = 0;
|
private int _start;
|
||||||
private int _limit = 2;
|
private int _limit = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,14 +35,15 @@ public class NewsFeedHelper extends HelperBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getEntries() {
|
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 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
|
* @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)
|
if (max <= 0)
|
||||||
max = Integer.MAX_VALUE;
|
max = Integer.MAX_VALUE;
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
@ -69,8 +70,11 @@ public class NewsFeedHelper extends HelperBase {
|
|||||||
fmt.setTimeZone(SystemVersion.getSystemTimeZone(ctx));
|
fmt.setTimeZone(SystemVersion.getSystemTimeZone(ctx));
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (NewsEntry entry : entries) {
|
for (NewsEntry entry : entries) {
|
||||||
if (i++ < start)
|
if (i < start)
|
||||||
continue;
|
continue;
|
||||||
|
if (i > start && entry.updated > 0 && ageLimit > 0 &&
|
||||||
|
entry.updated < ctx.clock().now() - ageLimit)
|
||||||
|
break;
|
||||||
buf.append("<div class=\"newsentry\"><h3>");
|
buf.append("<div class=\"newsentry\"><h3>");
|
||||||
if (entry.updated > 0) {
|
if (entry.updated > 0) {
|
||||||
Date date = new Date(entry.updated);
|
Date date = new Date(entry.updated);
|
||||||
@ -91,7 +95,7 @@ public class NewsFeedHelper extends HelperBase {
|
|||||||
buf.append("</h3>\n<div class=\"newscontent\">\n")
|
buf.append("</h3>\n<div class=\"newscontent\">\n")
|
||||||
.append(entry.content)
|
.append(entry.content)
|
||||||
.append("\n</div></div>\n");
|
.append("\n</div></div>\n");
|
||||||
if (i >= start + max)
|
if (++i >= start + max)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,8 @@ public class NewsHelper extends ContentHelper {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getContent() {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
// 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;
|
||||||
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) {
|
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&consoleNonce=")
|
buf.append("<li><a href=\"/?news=1&consoleNonce=")
|
||||||
.append(consoleNonce)
|
.append(consoleNonce)
|
||||||
.append("\">");
|
.append("\">");
|
||||||
|
Reference in New Issue
Block a user