forked from I2P_Developers/i2p.i2p
2005-12-19 jrandom
* I2PSnark logging, disconnect old inactive peers rather than new ones,
memory usage reduction, better OOM handling, and a shared connection
acceptor.
* Cleaned up the Syndie blog page and the resulting filters (viewing a
blog from the blog page shows threads started by the selected author,
not those that they merely participate in)
This commit is contained in:
@@ -291,6 +291,7 @@ public class ArchiveIndex {
|
||||
if (!blog.equals(summary.blog))
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( (tag != null) && (tag.trim().length() > 0) ) {
|
||||
if (!tag.equals(summary.tag)) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
@@ -315,17 +316,21 @@ public class ArchiveIndex {
|
||||
|
||||
for (int j = 0; j < summary.entries.size(); j++) {
|
||||
EntrySummary entry = (EntrySummary)summary.entries.get(j);
|
||||
if (entry.entry.getEntryId() < lowestEntryId)
|
||||
if (entry.entry.getEntryId() < lowestEntryId) {
|
||||
long daysAgo1 = entry.entry.getEntryId() / (24*60*60*1000l);
|
||||
long daysAgo2 = lowestEntryId / (24*60*60*1000l);
|
||||
continue;
|
||||
String k = (Long.MAX_VALUE-entry.entry.getEntryId()) + "-" + entry.entry.getKeyHash().toBase64();
|
||||
ordered.put(k, entry.entry);
|
||||
//System.err.println("Including match: " + k);
|
||||
} else {
|
||||
String k = (Long.MAX_VALUE-entry.entry.getEntryId()) + "-" + entry.entry.getKeyHash().toBase64();
|
||||
ordered.put(k, entry.entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Iterator iter = ordered.values().iterator(); iter.hasNext(); ) {
|
||||
BlogURI entry = (BlogURI)iter.next();
|
||||
if (entry.getEntryId() < lowestEntryId)
|
||||
if (entry.getEntryId() < lowestEntryId) {
|
||||
continue;
|
||||
}
|
||||
if (!out.contains(entry))
|
||||
out.add(entry);
|
||||
}
|
||||
|
||||
@@ -679,7 +679,7 @@ public abstract class BaseServlet extends HttpServlet {
|
||||
for (Iterator iter = names.iterator(); iter.hasNext(); ) {
|
||||
String name = (String) iter.next();
|
||||
PetName pn = db.getByName(name);
|
||||
if ("syndieblog".equals(pn.getProtocol())) {
|
||||
if ("syndieblog".equals(pn.getProtocol()) && pn.isMember(FilteredThreadIndex.GROUP_FAVORITE)) {
|
||||
if ( (author != null) && (author.equals(pn.getLocation())) )
|
||||
out.write("<option value=\"" + pn.getLocation() + "\" selected=\"true\">Threads " + name + " posted in</option>\n");
|
||||
else
|
||||
@@ -1151,6 +1151,16 @@ public abstract class BaseServlet extends HttpServlet {
|
||||
"}\n" +
|
||||
".postReplyOptions {\n" +
|
||||
" background-color: #BBBBFF;\n" +
|
||||
"}\n" +
|
||||
".syndieBlogFavorites {\n" +
|
||||
" float: left;\n" +
|
||||
" margin: 5px 0px 0 0;\n" +
|
||||
" display: inline;\n" +
|
||||
"}\n" +
|
||||
".syndieBlogList {\n" +
|
||||
" float: right;\n" +
|
||||
" margin: 5px 0px 0 0;\n" +
|
||||
" display: inline;\n" +
|
||||
"}\n";
|
||||
|
||||
|
||||
|
||||
@@ -19,9 +19,35 @@ import net.i2p.syndie.sml.*;
|
||||
*
|
||||
*/
|
||||
public class ViewBlogsServlet extends BaseServlet {
|
||||
private static final int MAX_AUTHORS_AT_ONCE = 100;
|
||||
private static final int MAX_AUTHORS_AT_ONCE = 20;
|
||||
private static final int MAX_TAGS = 50;
|
||||
|
||||
/** renders the posts from the last 3 days */
|
||||
private String getViewBlogLink(Hash blog, long lastPost) {
|
||||
long dayBegin = BlogManager.instance().getDayBegin();
|
||||
int daysAgo = 2;
|
||||
if ( (lastPost > 0) && (dayBegin - 3*24*60*6081000 > lastPost) ) // last post was old 3 days ago
|
||||
daysAgo = (int)((dayBegin - lastPost + 24*60*60*1000-1)/(24*60*60*1000));
|
||||
daysAgo++;
|
||||
return getControlTarget() + "?" + ThreadedHTMLRenderer.PARAM_AUTHOR + '=' + blog.toBase64()
|
||||
+ '&' + ThreadedHTMLRenderer.PARAM_THREAD_AUTHOR + "=true&daysBack=" + daysAgo;
|
||||
}
|
||||
|
||||
private String getPostDate(long when) {
|
||||
String age = null;
|
||||
long dayBegin = BlogManager.instance().getDayBegin();
|
||||
long postId = when;
|
||||
if (postId >= dayBegin) {
|
||||
age = "today";
|
||||
} else if (postId >= dayBegin - 24*60*60*1000) {
|
||||
age = "yesterday";
|
||||
} else {
|
||||
int daysAgo = (int)((dayBegin - postId + 24*60*60*1000-1)/(24*60*60*1000));
|
||||
age = daysAgo + " days ago";
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index,
|
||||
int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
|
||||
TreeSet orderedRoots = new TreeSet(new NewestEntryFirstComparator());
|
||||
@@ -35,8 +61,45 @@ public class ViewBlogsServlet extends BaseServlet {
|
||||
|
||||
TreeSet tags = new TreeSet();
|
||||
List writtenAuthors = new ArrayList();
|
||||
out.write("<tr><td colspan=\"3\"><b>Blogs:</b></td></tr>\n");
|
||||
out.write("<tr><td colspan=\"3\">");
|
||||
|
||||
|
||||
out.write("<tr><td colspan=\"3\" valign=\"top\" align=\"left\"><span class=\"syndieBlogFavorites\">");
|
||||
if ( (user != null) && (user.getAuthenticated()) ) {
|
||||
out.write("<b>Favorite blogs:</b><br />\n");
|
||||
out.write("<a href=\"" + getViewBlogLink(user.getBlog(), user.getLastMetaEntry())
|
||||
+ "\" title=\"View your blog\">Your blog</a><br />\n");
|
||||
|
||||
PetNameDB db = user.getPetNameDB();
|
||||
for (Iterator iter = orderedRoots.iterator(); iter.hasNext() && writtenAuthors.size() < MAX_AUTHORS_AT_ONCE; ) {
|
||||
BlogURI uri= (BlogURI)iter.next();
|
||||
if (writtenAuthors.contains(uri.getKeyHash())) {
|
||||
// skip
|
||||
} else {
|
||||
PetName pn = db.getByLocation(uri.getKeyHash().toBase64());
|
||||
if (pn != null) {
|
||||
if (pn.isMember(FilteredThreadIndex.GROUP_FAVORITE)) {
|
||||
out.write("<a href=\"" + getViewBlogLink(uri.getKeyHash(), uri.getEntryId())
|
||||
+ "\" title=\"View " + HTMLRenderer.sanitizeTagParam(pn.getName()) +"'s blog\">");
|
||||
out.write(HTMLRenderer.sanitizeString(pn.getName(), 32));
|
||||
out.write("</a> (" + getPostDate(uri.getEntryId()) + ")<br />\n");
|
||||
writtenAuthors.add(uri.getKeyHash());
|
||||
} else if (pn.isMember(FilteredThreadIndex.GROUP_IGNORE)) {
|
||||
// ignore 'em
|
||||
writtenAuthors.add(uri.getKeyHash());
|
||||
} else {
|
||||
// bookmarked, but not a favorite... leave them for later
|
||||
}
|
||||
} else {
|
||||
// not bookmarked, leave them for later
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out.write("</span>\n");
|
||||
|
||||
// now for the non-bookmarked people
|
||||
out.write("<span class=\"syndieBlogList\">");
|
||||
out.write("<b>Most recently updated blogs:</b><br />\n");
|
||||
for (Iterator iter = orderedRoots.iterator(); iter.hasNext() && writtenAuthors.size() < MAX_AUTHORS_AT_ONCE; ) {
|
||||
BlogURI uri= (BlogURI)iter.next();
|
||||
String curTags[] = archive.getEntry(uri).getTags();
|
||||
@@ -67,18 +130,17 @@ public class ViewBlogsServlet extends BaseServlet {
|
||||
age = daysAgo + " days ago";
|
||||
}
|
||||
|
||||
out.write("<a href=\"" + getControlTarget() + "?"
|
||||
+ ThreadedHTMLRenderer.PARAM_AUTHOR + '=' + uri.getKeyHash().toBase64()
|
||||
+ "&" + ThreadedHTMLRenderer.PARAM_THREAD_AUTHOR + "=true&"
|
||||
+ "\" title=\"Posts by " + trim(HTMLRenderer.sanitizeTagParam(name), 32)
|
||||
+ ", last post " + age + "\">");
|
||||
out.write("<a href=\"" + getViewBlogLink(uri.getKeyHash(), uri.getEntryId())
|
||||
+ "\" title=\"View " + trim(HTMLRenderer.sanitizeTagParam(name), 32)
|
||||
+ "'s blog\">");
|
||||
out.write(HTMLRenderer.sanitizeString(desc, 32));
|
||||
out.write("</a> \n");
|
||||
out.write("</a> (" + getPostDate(uri.getEntryId()) + ")<br />\n");
|
||||
writtenAuthors.add(uri.getKeyHash());
|
||||
}
|
||||
}
|
||||
out.write("</td></tr>\n");
|
||||
|
||||
out.write("</span>\n");
|
||||
/*
|
||||
out.write("<tr><td colspan=\"3\"><b>Topics:</b></td></tr>\n");
|
||||
out.write("<tr><td colspan=\"3\">");
|
||||
for (Iterator iter = tags.iterator(); iter.hasNext(); ) {
|
||||
@@ -88,6 +150,7 @@ public class ViewBlogsServlet extends BaseServlet {
|
||||
out.write(HTMLRenderer.sanitizeString(tag, 32));
|
||||
out.write("</a> ");
|
||||
}
|
||||
*/
|
||||
out.write("</td></tr>\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -54,19 +54,20 @@ public class ViewThreadedServlet extends BaseServlet {
|
||||
String tags = req.getParameter(ThreadedHTMLRenderer.PARAM_TAGS);
|
||||
String post = req.getParameter(ThreadedHTMLRenderer.PARAM_VIEW_POST);
|
||||
String thread = req.getParameter(ThreadedHTMLRenderer.PARAM_VIEW_THREAD);
|
||||
boolean threadAuthorOnly = Boolean.valueOf(req.getParameter(ThreadedHTMLRenderer.PARAM_THREAD_AUTHOR) + "").booleanValue();
|
||||
|
||||
long dayBegin = BlogManager.instance().getDayBegin();
|
||||
String daysStr = req.getParameter(ThreadedHTMLRenderer.PARAM_DAYS_BACK);
|
||||
int days = 1;
|
||||
try {
|
||||
if (daysStr != null)
|
||||
days = Integer.parseInt(daysStr);
|
||||
} catch (NumberFormatException nfe) {
|
||||
days = 1;
|
||||
}
|
||||
dayBegin -= (days-1) * 24*60*60*1000l;
|
||||
|
||||
if ( (author != null) && empty(post) && empty(thread) ) {
|
||||
long dayBegin = BlogManager.instance().getDayBegin();
|
||||
String daysStr = req.getParameter(ThreadedHTMLRenderer.PARAM_DAYS_BACK);
|
||||
int days = 1;
|
||||
try {
|
||||
if (daysStr != null)
|
||||
days = Integer.parseInt(daysStr);
|
||||
} catch (NumberFormatException nfe) {
|
||||
days = 1;
|
||||
}
|
||||
dayBegin -= (days-1) * 24*60*60*1000;
|
||||
|
||||
ArchiveIndex aindex = archive.getIndex();
|
||||
PetNameDB db = user.getPetNameDB();
|
||||
if ("favorites".equals(author)) {
|
||||
@@ -91,6 +92,22 @@ public class ViewThreadedServlet extends BaseServlet {
|
||||
if ( (key != null) && (key.length == Hash.HASH_LENGTH) ) {
|
||||
loc.setData(key);
|
||||
aindex.selectMatchesOrderByEntryId(rv, loc, tags, dayBegin);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
// how inefficient can we get?
|
||||
if (threadAuthorOnly && (rv.size() > 0)) {
|
||||
// lets filter out any posts that are not roots
|
||||
for (int i = 0; i < rv.size(); i++) {
|
||||
BlogURI curURI = (BlogURI)rv.get(i);
|
||||
ThreadNode node = index.getNode(curURI);
|
||||
if ( (node != null) && (node.getParent() == null) ) {
|
||||
// ok, its a root
|
||||
} else {
|
||||
rv.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,6 +152,7 @@ public class ViewThreadedServlet extends BaseServlet {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user