Changeset 35b75a7


Ignore:
Timestamp:
Dec 3, 2005 7:03:44 PM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
fef57897
Parents:
1c6c3979
git-author:
jrandom <jrandom> (12/03/05 19:03:44)
git-committer:
zzz <zzz@…> (12/03/05 19:03:44)
Message:

2005-12-03 jrandom

  • Added support for a 'most recent posts' view that CofE requested, which includes the ability to filter by age (e.g. posts by your favorite authors in the last 5 days).
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • apps/syndie/java/src/net/i2p/syndie/data/ArchiveIndex.java

    r1c6c3979 r35b75a7  
    282282     */
    283283    public void selectMatchesOrderByEntryId(List out, Hash blog, String tag) {
     284        selectMatchesOrderByEntryId(out, blog, tag, 0);
     285    }
     286    public void selectMatchesOrderByEntryId(List out, Hash blog, String tag, long lowestEntryId) {
    284287        TreeMap ordered = new TreeMap();
    285288        for (int i = 0; i < _blogs.size(); i++) {
     
    289292                    continue;
    290293            }
    291             if (tag != null) {
     294            if ( (tag != null) && (tag.trim().length() > 0) ) {
    292295                if (!tag.equals(summary.tag)) {
    293296                    if (_log.shouldLog(Log.DEBUG))
     
    313316            for (int j = 0; j < summary.entries.size(); j++) {
    314317                EntrySummary entry = (EntrySummary)summary.entries.get(j);
     318                if (entry.entry.getEntryId() < lowestEntryId)
     319                    continue;
    315320                String k = (Long.MAX_VALUE-entry.entry.getEntryId()) + "-" + entry.entry.getKeyHash().toBase64();
    316321                ordered.put(k, entry.entry);
     
    320325        for (Iterator iter = ordered.values().iterator(); iter.hasNext(); ) {
    321326            BlogURI entry = (BlogURI)iter.next();
     327            if (entry.getEntryId() < lowestEntryId)
     328                continue;
    322329            if (!out.contains(entry))
    323330                out.add(entry);
  • apps/syndie/java/src/net/i2p/syndie/data/BlogURI.java

    r1c6c3979 r35b75a7  
    1010    private Hash _blogHash;
    1111    private long _entryId;
     12   
     13    public static final Comparator COMPARATOR = new NewestFirstComparator();
    1214   
    1315    public BlogURI() {
     
    9698            System.err.println("Not a match: [" + uri + "] != [" + u.toString() + "]");
    9799    }
     100
     101    /**
     102     * Order the BlogURIs by entryId, with the highest entryId first
     103     */
     104    private static class NewestFirstComparator implements Comparator {       
     105        public int compare(Object lhs, Object rhs) {
     106            BlogURI l = (BlogURI)lhs;
     107            BlogURI r = (BlogURI)rhs;
     108            if (l.getEntryId() > r.getEntryId())
     109                return -1;
     110            else if (l.getEntryId() < r.getEntryId())
     111                return 1;
     112            else // same date, compare by blog hash (aka randomly)
     113                return DataHelper.compareTo(l.getKeyHash().getData(), r.getKeyHash().getData());
     114        }
     115    }
    98116}
  • apps/syndie/java/src/net/i2p/syndie/sml/ThreadedHTMLRenderer.java

    r1c6c3979 r35b75a7  
    4141    public static final String PARAM_TAGS = "tags";
    4242    public static final String PARAM_AUTHOR = "author";
     43    /** search back through the blog for entries this many days */
     44    public static final String PARAM_DAYS_BACK = "daysBack";
    4345    // parameters for editing one's profile
    4446    public static final String PARAM_PROFILE_NAME = "profileName";
     
    447449        if ( (inReplyTo != null) && (inReplyTo.trim().length() > 0) ) {
    448450            BlogURI replyURI = new BlogURI(inReplyTo);
    449             if (replyURI.getEntryId() > 0)
    450                 _postBodyBuffer.append(" <a ").append(getClass("summDetailParent")).append(" href=\"").append(getPageURL(replyURI.getKeyHash(), null, replyURI.getEntryId(), 0, 0, true, true)).append("\">(view parent)</a><br />\n");
     451            if (replyURI.getEntryId() > 0) {
     452                _postBodyBuffer.append(" <a ").append(getClass("summDetailParent"));
     453                _postBodyBuffer.append(" href=\"");
     454                _postBodyBuffer.append(getPageURL(replyURI.getKeyHash(), null, replyURI.getEntryId(), 0, 0, true, true));
     455                _postBodyBuffer.append("\">(view parent)</a><br />\n");
     456            }
    451457        }
    452458
     
    488494        StringBuffer buf = new StringBuffer(128);
    489495        buf.append(_baseURI).append('?');
     496        String entry = null;
    490497        if ( (blog != null) && (entryId > 0) ) {
    491             buf.append(PARAM_VIEW_POST).append('=').append(Base64.encode(blog.getData())).append('/').append(entryId).append('&');
     498            entry = blog.toBase64() + '/' + entryId;
     499            buf.append(PARAM_VIEW_THREAD).append('=').append(entry).append('&');
    492500            buf.append(PARAM_VISIBLE).append('=').append(Base64.encode(blog.getData())).append('/').append(entryId).append('&');
    493501        } else if (blog != null) {
     
    496504        if (tag != null)
    497505            buf.append(PARAM_TAGS).append('=').append(sanitizeTagParam(tag)).append('&');
     506        if ( (blog != null) && (entryId > 0) )
     507            buf.append("#blog://").append(entry);
    498508        return buf.toString();
    499509    }
  • apps/syndie/java/src/net/i2p/syndie/web/BaseServlet.java

    r1c6c3979 r35b75a7  
    7878        resp.setCharacterEncoding("UTF-8");
    7979        resp.setContentType("text/html;charset=UTF-8");
     80        resp.setHeader("cache-control", "no-cache");
     81        resp.setHeader("pragma", "no-cache");
    8082       
    8183        User user = (User)req.getSession().getAttribute("user");
     
    491493    protected void renderBegin(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index) throws IOException {
    492494        out.write("<html>\n<head><title>" + getTitle() + "</title>\n");
     495        out.write("<meta http-equiv=\"cache-control\" content=\"no-cache\" />");
     496        out.write("<meta http-equiv=\"pragma\" content=\"no-cache\" />");
    493497        out.write("<style>");
    494498        out.write(STYLE_HTML);
     
    554558        // post and visible are skipped since we aren't good at filtering by tag when the offset will
    555559        // skip around randomly.  at least, not yet.
    556         SKIP_TAGS.add("visible");
     560        SKIP_TAGS.add(ThreadedHTMLRenderer.PARAM_VISIBLE);
    557561        //SKIP_TAGS.add("post");
    558562        //SKIP_TAGS.add("thread");
    559         SKIP_TAGS.add("offset"); // if we are adjusting the filter, ignore the previous offset
     563        SKIP_TAGS.add(ThreadedHTMLRenderer.PARAM_OFFSET); // if we are adjusting the filter, ignore the previous offset
     564        SKIP_TAGS.add(ThreadedHTMLRenderer.PARAM_DAYS_BACK);
    560565        SKIP_TAGS.add("addLocation");
    561566        SKIP_TAGS.add("addGroup");
     
    598603        TreeSet names = new TreeSet(db.getNames());
    599604        out.write("<option value=\"\">Any authors</option>\n");
     605        if (user.getAuthenticated()) {
     606            if ("favorites".equals(author))
     607                out.write("<option selected=\"true\" value=\"favorites\">All recent posts by favorite authors</option>\n");
     608            else
     609                out.write("<option value=\"favorites\">All recent posts by favorite authors</option>\n");
     610        }
    600611        if (user.getBlog() != null) {
    601612            if ( (author != null) && (author.equals(user.getBlog().toBase64())) )
     
    620631                  + "\" title=\"Threads are filtered to include only ones with posts containing these tags\" />\n");
    621632
     633        String days = req.getParameter(ThreadedHTMLRenderer.PARAM_DAYS_BACK);
     634        if (days == null)
     635            days = "";
     636        out.write("Age: <input type=\"text\" name=\"" + ThreadedHTMLRenderer.PARAM_DAYS_BACK + "\" size=\"2\" value=\"" + days
     637                  + "\" title=\"Posts are filtered to include only ones which were made within this many days ago\" /> days\n");
     638       
    622639        out.write("<input type=\"submit\" name=\"action\" value=\"Go\" />\n");
    623640        out.write("</td><td class=\"controlBarRight\" width=\"1%\">");
  • apps/syndie/java/src/net/i2p/syndie/web/ViewThreadedServlet.java

    r1c6c3979 r35b75a7  
    2222    protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index,
    2323                                        int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
    24         List posts = getPosts(archive, req, index);
     24        List posts = getPosts(user, archive, req, index);
    2525        renderBody(user, req, out, index, archive, posts);
    2626       
     
    4747    }
    4848   
    49     private List getPosts(Archive archive, HttpServletRequest req, ThreadIndex index) {
     49    private List getPosts(User user, Archive archive, HttpServletRequest req, ThreadIndex index) {
    5050        List rv = new ArrayList(1);
     51        String author = req.getParameter(ThreadedHTMLRenderer.PARAM_AUTHOR);
     52        String tags = req.getParameter(ThreadedHTMLRenderer.PARAM_TAGS);
     53        if (author != null) {
     54            long dayBegin = BlogManager.instance().getDayBegin();
     55            String daysStr = req.getParameter(ThreadedHTMLRenderer.PARAM_DAYS_BACK);
     56            int days = 1;
     57            try {
     58                if (daysStr != null)
     59                    days = Integer.parseInt(daysStr);
     60            } catch (NumberFormatException nfe) {
     61                days = 1;
     62            }
     63            dayBegin -= (days-1) * 24*60*60*1000;
     64           
     65            ArchiveIndex aindex = archive.getIndex();
     66            PetNameDB db = user.getPetNameDB();
     67            if ("favorites".equals(author)) {
     68                for (Iterator nameIter = db.getNames().iterator(); nameIter.hasNext(); ) {
     69                    PetName pn = db.getByName((String)nameIter.next());
     70                    if (pn.isMember(FilteredThreadIndex.GROUP_FAVORITE) && AddressesServlet.PROTO_BLOG.equals(pn.getProtocol()) ) {
     71                        Hash loc = new Hash();
     72                        byte key[] = Base64.decode(pn.getLocation());
     73                        if ( (key != null) && (key.length == Hash.HASH_LENGTH) ) {
     74                            loc.setData(key);
     75                            aindex.selectMatchesOrderByEntryId(rv, loc, tags, dayBegin);
     76                        }
     77                    }
     78                }
     79                Collections.sort(rv, BlogURI.COMPARATOR);
     80            } else {
     81                Hash loc = new Hash();
     82                byte key[] = Base64.decode(author);
     83                if ( (key != null) && (key.length == Hash.HASH_LENGTH) ) {
     84                    loc.setData(key);
     85                    aindex.selectMatchesOrderByEntryId(rv, loc, tags, dayBegin);
     86                }
     87            }
     88        }
     89       
    5190        String post = req.getParameter(ThreadedHTMLRenderer.PARAM_VIEW_POST);
    5291        BlogURI uri = getAsBlogURI(post);
  • history.txt

    r1c6c3979 r35b75a7  
    1 $Id: history.txt,v 1.342 2005/12/03 00:41:25 jrandom Exp $
     1$Id: history.txt,v 1.343 2005/12/03 12:33:35 jrandom Exp $
     2
     32005-12-03  jrandom
     4    * Added support for a 'most recent posts' view that CofE requested, which
     5      includes the ability to filter by age (e.g. posts by your favorite
     6      authors in the last 5 days).
    27
    382005-12-03  jrandom
Note: See TracChangeset for help on using the changeset viewer.