]> code.citadel.org Git - citadel.git/blobdiff - webcit/blogview_renderer.c
blog renderer
[citadel.git] / webcit / blogview_renderer.c
index 42663786a592e6f09b5bb4a21ac4b382846399a5..cd2a52efd3d63719959ad4fd0eb18c192afc68d6 100644 (file)
@@ -29,8 +29,8 @@
 
 struct blogpost {
        long msgnum;
-       StrBuf *id;
-       StrBuf *refs;
+       int id;
+       int refs;
        int comment_count;
 };
 
@@ -91,8 +91,8 @@ int blogview_LoadMsgFromServer(SharedMessageStatus *Stat,
        }
 
        BLOG->msgs[BLOG->num_msgs++].msgnum = Msg->msgnum;
-       BLOG->msgs[BLOG->num_msgs].id = NULL;
-       BLOG->msgs[BLOG->num_msgs].refs = NULL;
+       BLOG->msgs[BLOG->num_msgs].id = 0;
+       BLOG->msgs[BLOG->num_msgs].refs = 0;
        BLOG->msgs[BLOG->num_msgs].comment_count = 0;
 
        return 200;
@@ -121,22 +121,26 @@ int blogview_sortfunc(const void *s1, const void *s2) {
 void blogview_learn_thread_references(struct blogpost *bp)
 {
        StrBuf *Buf;
+       StrBuf *r;
        Buf = NewStrBuf();
+       r = NewStrBuf();
        serv_printf("MSG0 %ld|1", bp->msgnum);          /* top level citadel headers only */
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) {
                while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
                        if (!strncasecmp(ChrPtr(Buf), "msgn=", 5)) {
-                               bp->id = NewStrBufDup(Buf);
-                               StrBufCutLeft(bp->id, 5);
+                               StrBufCutLeft(Buf, 5);
+                               bp->id = HashLittle(ChrPtr(Buf), StrLength(Buf));
                        }
                        else if (!strncasecmp(ChrPtr(Buf), "wefw=", 5)) {
-                               bp->refs = NewStrBufDup(Buf);
-                               StrBufCutLeft(bp->refs, 5);
+                               StrBufCutLeft(Buf, 5);          /* trim the field name */
+                               StrBufExtract_token(r, Buf, 0, '|');
+                               bp->refs = HashLittle(ChrPtr(r), StrLength(r));
                        }
                }
        }
        FreeStrBuf(&Buf);
+       FreeStrBuf(&r);
 }
 
 
@@ -145,7 +149,7 @@ void blogview_learn_thread_references(struct blogpost *bp)
 int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
 {
        struct blogview *BLOG = (struct blogview *) *ViewSpecific;
-       int i;
+       int i, j;
 
        /* Pass #1 - sort */
        if (Stat->nummsgs > 0) {
@@ -154,30 +158,53 @@ int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
        }
 
        /* Pass #2 - learn thread references */
+       lprintf(9, "learning thread references\n");
        for (i=0; (i<BLOG->num_msgs); ++i) {
                if (BLOG->msgs[i].msgnum > 0L) {
                        blogview_learn_thread_references(&BLOG->msgs[i]);
                }
        }
 
-       /* FIXME here is where we should actually turn it into a thread tree */
+       /* Pass #3 - turn it into a thread tree */
+       /* FIXME implement this */
+
+       /* Pass #4 - render
+        * This will require several different modes:
+        * * Top level
+        * * Single story permalink
+        * * Comments
+        * * etc
+        */
 
-       /* Pass #3 - render */
        for (i=0; (i<BLOG->num_msgs); ++i) {
                if (BLOG->msgs[i].msgnum > 0L) {
-                       if (BLOG->msgs[i].refs == NULL) {
-                               wc_printf("<b>");
-                       }
-                       wc_printf("Message %d, #%ld, id '%s', refs '%s'",
+                       wc_printf("Message %d, #%ld, id %d, refs %d<br>\n",
                                i,
                                BLOG->msgs[i].msgnum,
-                               ChrPtr(BLOG->msgs[i].id),
-                               ChrPtr(BLOG->msgs[i].refs)
+                               BLOG->msgs[i].id,
+                               BLOG->msgs[i].refs
                        );
-                       if (BLOG->msgs[i].refs == NULL) {
-                               wc_printf("</b>");
+               }
+       }
+
+       wc_printf("<hr>\n");
+
+       for (i=0; (i<BLOG->num_msgs); ++i) {
+               if ((BLOG->msgs[i].msgnum > 0L) && (BLOG->msgs[i].refs == 0)) {
+                       const StrBuf *Mime;
+                       wc_printf("<b>Message %d, #%ld, id %d, refs %d</b><br>\n",
+                               i,
+                               BLOG->msgs[i].msgnum,
+                               BLOG->msgs[i].id,
+                               BLOG->msgs[i].refs
+                       );
+                       read_message(WC->WBuf, HKEY("view_message"), BLOG->msgs[i].msgnum, NULL, &Mime);
+                       for (j=0; (j<BLOG->num_msgs); ++j) {
+                               if (BLOG->msgs[j].refs == BLOG->msgs[i].id) {
+                                       wc_printf("     * comment %d<br>\n", j);
+                               }
                        }
-                       wc_printf("<br>\n");
+                       wc_printf("<hr>\n");
                }
        }
 
@@ -188,13 +215,8 @@ int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
 int blogview_Cleanup(void **ViewSpecific)
 {
        struct blogview *BLOG = (struct blogview *) *ViewSpecific;
-       int i;
 
        if (BLOG->alloc_msgs != 0) {
-               for (i=0; i<BLOG->num_msgs; ++i) {
-                       FreeStrBuf(&BLOG->msgs[i].id);
-                       FreeStrBuf(&BLOG->msgs[i].refs);
-               }
                free(BLOG->msgs);
        }
        free(BLOG);