]> code.citadel.org Git - citadel.git/blobdiff - webcit/blogview_renderer.c
Ok, *this* is the way we want it structured internally.
[citadel.git] / webcit / blogview_renderer.c
index 6ae055ece1a84d7a9252ffa1dbd74193cea202cf..8dc7036e509e21765960e8752e2f9e330a700a79 100644 (file)
  * Data which gets passed around between the various functions in this module
  *
  */
+
+struct blogpost {
+       long msgnum;
+       int id;
+       int refs;
+       int comment_count;
+};
+
 struct blogview {
-       long *msgs;             /* Array of msgnums for messages we are displaying */
+       struct blogpost *msgs;  /* Array of msgnums for messages we are displaying */
        int num_msgs;           /* Number of msgnums stored in 'msgs' */
        int alloc_msgs;         /* Currently allocated size of array */
 };
@@ -71,8 +79,8 @@ int blogview_LoadMsgFromServer(SharedMessageStatus *Stat,
 
        if (BLOG->alloc_msgs == 0) {
                BLOG->alloc_msgs = 1000;
-               BLOG->msgs = malloc(BLOG->alloc_msgs * sizeof(long));
-               memset(BLOG->msgs, 0, (BLOG->alloc_msgs * sizeof(long)) );
+               BLOG->msgs = malloc(BLOG->alloc_msgs * sizeof(struct blogpost));
+               memset(BLOG->msgs, 0, (BLOG->alloc_msgs * sizeof(struct blogpost)) );
        }
 
        /* Check our buffer size */
@@ -82,47 +90,129 @@ int blogview_LoadMsgFromServer(SharedMessageStatus *Stat,
                memset(&BLOG->msgs[BLOG->num_msgs], 0, ((BLOG->alloc_msgs - BLOG->num_msgs) * sizeof(long)) );
        }
 
-       BLOG->msgs[BLOG->num_msgs++] = Msg->msgnum;
+       BLOG->msgs[BLOG->num_msgs++].msgnum = Msg->msgnum;
+       BLOG->msgs[BLOG->num_msgs].id = 0;
+       BLOG->msgs[BLOG->num_msgs].refs = 0;
+       BLOG->msgs[BLOG->num_msgs].comment_count = 0;
 
        return 200;
 }
 
 
-int blogview_sortfunc(const void *s1, const void *s2) {
-       long l1;
-       long l2;
 
-       l1 = *(long *)(s1);
-       l2 = *(long *)(s2);
+/*
+ * Sort a list of 'struct blogpost' objects by newest-to-oldest msgnum.
+ */
+int blogview_sortfunc(const void *s1, const void *s2) {
+       struct blogpost *l1 = (struct blogpost *)(s1);
+       struct blogpost *l2 = (struct blogpost *)(s2);
 
-       if (l1 > l2) return(+1);
-       if (l1 < l2) return(-1);
+       if (l1->msgnum > l2->msgnum) return(-1);
+       if (l1->msgnum < l2->msgnum) return(+1);
        return(0);
 }
 
 
-int blogview_RenderView_or_Tail(SharedMessageStatus *Stat, 
-                              void **ViewSpecific, 
-                              long oper)
+
+/*
+ * Given a 'struct blogpost' containing a msgnum, populate the id
+ * and refs fields by fetching them from the Citadel server
+ */
+void blogview_learn_thread_references(struct blogpost *bp)
 {
-       struct blogview *BLOG = (struct blogview *) *ViewSpecific;
-       int i;
-       const StrBuf *Mime;
+       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)) {
+                               StrBufCutLeft(Buf, 5);
+                               wc_printf("id %s, ", ChrPtr(Buf));
+                               bp->id = HashLittle(ChrPtr(Buf), StrLength(Buf));
+                       }
+                       else if (!strncasecmp(ChrPtr(Buf), "wefw=", 5)) {
+                               StrBufCutLeft(Buf, 5);          /* trim the field name */
+                               wc_printf("refs %s, ", ChrPtr(Buf));
+                               StrBufExtract_token(r, Buf, 0, '|');
+                               wc_printf("topref %s, ", ChrPtr(r));
+                               bp->refs = HashLittle(ChrPtr(r), StrLength(r));
+                       }
+               }
+               wc_printf("<br>\n");
+       }
+       FreeStrBuf(&Buf);
+       FreeStrBuf(&r);
+}
+
+
 
-       wc_printf("<div class=\"fix_scrollbar_bug\">");
 
+int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
+{
+       struct blogview *BLOG = (struct blogview *) *ViewSpecific;
+       int i, j;
+
+       /* Pass #1 - sort */
        if (Stat->nummsgs > 0) {
                lprintf(9, "sorting %d messages\n", BLOG->num_msgs);
-               qsort(BLOG->msgs, (size_t)(BLOG->num_msgs), sizeof(long), blogview_sortfunc);
+               qsort(BLOG->msgs, (size_t)(BLOG->num_msgs), sizeof(struct blogpost), blogview_sortfunc);
+       }
+
+       /* 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]);
+               }
        }
 
+       /* 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
+        */
+
+       wc_printf("<hr>\n");
+
+       for (i=0; (i<BLOG->num_msgs); ++i) {
+               if (BLOG->msgs[i].msgnum > 0L) {
+                       wc_printf("Message %d, #%ld, id %d, refs %d<br>\n",
+                               i,
+                               BLOG->msgs[i].msgnum,
+                               BLOG->msgs[i].id,
+                               BLOG->msgs[i].refs
+                       );
+               }
+       }
+
+       wc_printf("<hr>\n");
+
        for (i=0; (i<BLOG->num_msgs); ++i) {
-               if (BLOG->msgs[i] > 0L) {
-                       read_message(WC->WBuf, HKEY("view_message"), BLOG->msgs[i], NULL, &Mime);
+               if (BLOG->msgs[i].msgnum > 0L) {
+                       if (BLOG->msgs[i].refs == 0) {
+                               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
+                               );
+                               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("</div>\n");
        return(0);
 }
 
@@ -151,7 +241,7 @@ InitModule_BLOGVIEWRENDERERS
                NULL,
                NULL, 
                blogview_LoadMsgFromServer,
-               blogview_RenderView_or_Tail,
+               blogview_render,
                blogview_Cleanup
        );
 }