Console: Only display news if a new entry is found

not simply when a new file is downloaded
This commit is contained in:
zzz
2022-07-09 09:41:13 -04:00
parent 73c8ee826e
commit a18a5136b7
6 changed files with 52 additions and 11 deletions

View File

@ -90,7 +90,7 @@ public class NewsManager implements ClientApp {
* Does NOT update the NewsEntry list.
*
* @param entries each one should be "entry" at the root
* @return success
* @return true if any new entry was written (not if changed)
*/
public synchronized boolean storeEntries(List<Node> entries) {
return PersistNews.store(_context, entries);

View File

@ -46,7 +46,7 @@ class PersistNews {
* Old entries are always overwritten, as they may change even without the updated date changing.
*
* @param entries each one should be "entry" at the root
* @return success
* @return true if any new entry was written (not if changed)
*/
public static boolean store(I2PAppContext ctx, List<Node> entries) {
Log log = ctx.logManager().getLog(PersistNews.class);
@ -54,7 +54,7 @@ class PersistNews {
if (!dir.exists())
dir.mkdirs();
StringBuilder buf = new StringBuilder();
boolean rv = true;
boolean rv = false;
for (Node entry : entries) {
Node nid = entry.getNode("id");
if (nid == null) {
@ -70,6 +70,8 @@ class PersistNews {
}
String name = idToName(ctx, id);
File file = new File(dir, name);
if (!rv && !file.exists())
rv = true;
Writer out = null;
try {
out = new OutputStreamWriter(new GZIPOutputStream(new SecureFileOutputStream(file)));
@ -80,7 +82,6 @@ class PersistNews {
} catch (IOException ioe) {
if (log.shouldWarn())
log.warn("failed store to " + file, ioe);
rv = false;
} finally {
if (out != null) try { out.close(); } catch (IOException ioe) {}
}

View File

@ -73,6 +73,8 @@ class NewsFetcher extends UpdateRunner {
/** is the news newer */
private boolean _isNewer;
private boolean _success;
/** did we get a new news entry */
private boolean _gotNewEntry;
private static final String TEMP_NEWS_FILE = "news.xml.temp";
static final String PROP_BLOCKLIST_TIME = "router.blocklistVersion";
@ -141,10 +143,14 @@ class NewsFetcher extends UpdateRunner {
if (get.fetch()) {
int status = get.getStatusCode();
if (status == 200 || status == 304) {
Map<String, String> opts = new HashMap<String, String>(2);
Map<String, String> opts = new HashMap<String, String>(3);
opts.put(NewsHelper.PROP_LAST_CHECKED, Long.toString(start));
if (status == 200 && _isNewer)
opts.put(NewsHelper.PROP_LAST_UPDATED, Long.toString(_newLastModified));
if (status == 200 && _isNewer) {
String lastMod = Long.toString(_newLastModified);
opts.put(NewsHelper.PROP_LAST_UPDATED, lastMod);
if (_gotNewEntry)
opts.put(NewsHelper.PROP_LAST_NEW_ENTRY, lastMod);
}
_context.router().saveConfig(opts, null);
return;
}
@ -526,7 +532,7 @@ class NewsFetcher extends UpdateRunner {
if (nmgr != null) {
nmgr.addEntries(entries);
List<Node> nodes = NewsXMLParser.getNodes(root, "entry");
nmgr.storeEntries(nodes);
_gotNewEntry = nmgr.storeEntries(nodes);
}
}
// Persist any new CRL entries

View File

@ -25,6 +25,8 @@ public class NewsHelper extends ContentHelper {
public static final String PROP_LAST_CHECKED = "routerconsole.newsLastChecked";
/** @since 0.9.4 */
public static final String PROP_LAST_UPDATED = "routerconsole.newsLastUpdated";
/** @since 0.9.55 */
public static final String PROP_LAST_NEW_ENTRY = "routerconsole.newsLastNewEntry";
/**
* Default true
* @since 0.9.21
@ -256,7 +258,7 @@ public class NewsHelper extends ContentHelper {
* @since 0.9.4
*/
public static boolean shouldShowNews(RouterContext ctx) {
long lastUpdated = lastUpdated(ctx);
long lastUpdated = lastNewEntry(ctx);
if (lastUpdated <= 0)
return true;
long last = ctx.getProperty(PROP_LAST_HIDDEN, 0L);
@ -276,7 +278,7 @@ public class NewsHelper extends ContentHelper {
* @since 0.9.4
*/
public static void showNews(RouterContext ctx, boolean yes) {
long stamp = yes ? 0 : lastUpdated(ctx);
long stamp = yes ? 0 : lastNewEntry(ctx);
ctx.router().saveConfig(PROP_LAST_HIDDEN, Long.toString(stamp));
}
@ -370,4 +372,17 @@ public class NewsHelper extends ContentHelper {
ctx.router().saveConfig(PROP_LAST_UPDATED, Long.toString(rv));
return rv;
}
/**
* When we last got a new news entry
* @since 0.9.55
*/
private static long lastNewEntry(RouterContext ctx) {
long rv = ctx.getProperty(PROP_LAST_NEW_ENTRY, 0L);
if (rv > 0)
return rv;
rv = lastUpdated(ctx);
ctx.router().saveConfig(PROP_LAST_NEW_ENTRY, Long.toString(rv));
return rv;
}
}

View File

@ -1,3 +1,22 @@
2022-07-09 zzz
* Console: Only display news if a new entry is found
* SSU2: Support other reason codes in destroy message
2022-07-08 zzz
* SSU: Initialize MTUs
* SSU2: Persist SSU2 tokens
* Transports: Don't lookup RI in wasUnreachable()
2022-07-05 zzz
* SSU2: Fix peer test throttling
2022-07-04 zzz
* Console: Add cancel button to netdb search form
* NetDB: Lookup handling cleanups
2022-07-02 zzz
* SSU: Remove copy of peers in idle timeout checker
2022-06-25 zzz
* SSU: MTU fixes for IPv6 and SSU2

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Git";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 9;
public final static long BUILD = 10;
/** for example "-test" */
public final static String EXTRA = "";