* Merged the new BBS view code, with an ifdef around it. Define NEW_BBS_VIEW if...
authorArt Cancro <ajc@citadel.org>
Mon, 14 Dec 2009 17:17:12 +0000 (17:17 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 14 Dec 2009 17:17:12 +0000 (17:17 +0000)
webcit/bbsview_renderer.c

index 958e28a92312fed9dc3a5cf91800e52c2582053b..bdaf4dbb879b063818921b81afb58cbad6b51354 100644 (file)
@@ -3,6 +3,18 @@
 #include "groupdav.h"
 
 
+
+/* We're jamming both of these in here so I can develop the new BBS view in-tree.
+ * Define NEW_BBS_BIEW to get the new, better, but unfinished and untested version.
+ *
+ */
+
+#ifndef NEW_BBS_VIEW
+
+
+/*** Code for the OLD bbs view ***/
+
+
 typedef struct _bbsview_stuct {
        StrBuf *BBViewToolBar;
        StrBuf *MessageDropdown;
@@ -273,3 +285,233 @@ InitModule_BBSVIEWRENDERERS
                bbsview_RenderView_or_Tail,
                bbsview_Cleanup);
 }
+
+
+
+
+
+#else /* NEW_BBS_VIEW */
+
+
+/*** Code for the NEW bbs view ***/
+
+
+
+/*
+ * Data which gets passed around between the various functions in this module
+ */
+struct bbsview {
+       long *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 */
+};
+
+
+/*
+ * Entry point for message read operations.
+ */
+int bbsview_GetParamsGetServerCall(SharedMessageStatus *Stat, 
+                                  void **ViewSpecific, 
+                                  long oper, 
+                                  char *cmd, 
+                                  long len)
+{
+       struct bbsview *BBS = malloc(sizeof(struct bbsview));
+       memset(BBS, 0, sizeof(struct bbsview));
+       *ViewSpecific = BBS;
+
+       Stat->defaultsortorder = 1;
+       Stat->startmsg = -1;
+       Stat->sortit = 1;
+       
+       rlid[oper].cmd(cmd, len);               /* this performs the server call to fetch the msg list */
+       
+       if (havebstr("maxmsgs")) {
+               Stat->maxmsgs = ibstr("maxmsgs");
+       }
+       if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS;
+       
+       if (havebstr("startmsg")) {
+               Stat->startmsg = lbstr("startmsg");
+       }
+       if (lbstr("SortOrder") == 2) {
+               Stat->reverse = 1;
+               Stat->num_displayed = -DEFAULT_MAXMSGS;
+       }
+       else {
+               Stat->reverse = 0;
+               Stat->num_displayed = DEFAULT_MAXMSGS;
+       }
+
+       return 200;
+}
+
+
+/*
+ * FIXME do we even need this?
+ */
+int bbsview_PrintViewHeader(SharedMessageStatus *Stat, void **ViewSpecific)
+{
+       return 200;
+}
+
+
+/*
+ * This function is called for every message in the list.
+ */
+int bbsview_LoadMsgFromServer(SharedMessageStatus *Stat, 
+                             void **ViewSpecific, 
+                             message_summary* Msg, 
+                             int is_new, 
+                             int i)
+{
+       struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
+
+       if (WC->is_ajax) {
+               begin_ajax_response();          /* for non-ajax, headers are output in messages.c */
+       }
+
+       if (BBS->num_msgs < Stat->maxmsgs) {
+
+               if (BBS->alloc_msgs == 0) {
+                       BBS->alloc_msgs = Stat->maxmsgs;
+                       BBS->msgs = malloc(BBS->alloc_msgs * sizeof(long));
+               }
+       
+               /* Theoretically this never happens because the initial allocation == maxmsgs */
+               if (BBS->num_msgs >= BBS->alloc_msgs) {
+                       BBS->alloc_msgs *= 2;
+                       BBS->msgs = realloc(BBS->msgs, (BBS->alloc_msgs * sizeof(long)));
+               }
+       
+               BBS->msgs[BBS->num_msgs++] = Msg->msgnum;
+       }
+       return 200;
+}
+
+int bbsview_sortfunc_reverse(const void *s1, const void *s2) {
+       long l1;
+       long l2;
+
+       l1 = *(long *)(s1);
+       l2 = *(long *)(s2);
+
+       if (l1 > l2) return(-1);
+       if (l1 < l2) return(+1);
+       return(0);
+}
+
+
+int bbsview_sortfunc_forward(const void *s1, const void *s2) {
+       long l1;
+       long l2;
+
+       l1 = *(long *)(s1);
+       l2 = *(long *)(s2);
+
+       if (l1 > l2) return(+1);
+       if (l1 < l2) return(-1);
+       return(0);
+}
+
+
+int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat, 
+                              void **ViewSpecific, 
+                              long oper)
+{
+       struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
+       int i;
+       const StrBuf *Mime;
+       char morediv[64];
+
+       lprintf(9, "bbsview_RenderView_or_Tail() has been called\n");
+
+       /* Handle the empty message set gracefully... */
+       if (Stat->nummsgs == 0) {
+               if (!WC->is_ajax) {
+                       wc_printf("<div class=\"nomsgs\"><br><em>");
+                       wc_printf(_("No messages here."));
+                       wc_printf("</em><br></div>\n");
+               }
+       }
+
+       /* Non-empty message set... */
+       else {
+               lprintf(9, "sorting %d messages\n", BBS->num_msgs);
+               qsort(BBS->msgs, (size_t)(BBS->num_msgs), sizeof(long), (Stat->reverse ? bbsview_sortfunc_reverse : bbsview_sortfunc_forward));
+       
+               for (i=0; i<BBS->num_msgs; ++i) {
+                       read_message(WC->WBuf, HKEY("view_message"), BBS->msgs[i], NULL, &Mime);
+               }
+
+       }
+
+       snprintf(morediv, sizeof morediv, "morediv%08lx%08x", time(NULL), rand());
+
+       if (!WC->is_ajax) {     /* only supply the script during the initial page load */
+          StrBufAppendPrintf(WC->trailing_javascript,
+               "       function moremsgs(target_div, gt, maxmsgs, sortorder) {                         \n"
+               "               $(target_div).innerHTML = '%s ... <img src=\"static/throbber.gif\">';   \n"
+               "               p = 'gt=' + gt + '&maxmsgs=' + maxmsgs                                  \n"
+               "                       + '&is_summary=0&SortOrder=' + sortorder + '&is_ajax=1'         \n"
+               "                       + '&r=' + CtdlRandomString();                                   \n"
+               "               new Ajax.Updater(target_div, 'readgt',                                  \n"
+               "                       { method: 'get', parameters: p, evalScripts: true } );          \n"
+               "       }                                                                               \n"
+               "",
+               _("Loading")
+          );
+       }
+
+       wc_printf("<div id=\"%s\">", morediv);
+       if (Stat->nummsgs > 0) {
+               wc_printf("<a href=\"javascript:moremsgs('%s', %ld, %ld, %d );\">",
+                       morediv,
+                       BBS->msgs[BBS->num_msgs-1],
+                       Stat->maxmsgs,
+                       (Stat->reverse ? 2 : 1)
+               );
+       
+               wc_printf("div \"%s\" - click for more messages<br><br><br><br>", morediv);
+               wc_printf("</a>");
+       }
+       else {
+               wc_printf("thththththat's all, folks!<br><br><br><br>");
+       }
+       wc_printf("</div>");
+
+       return(0);
+}
+
+
+int bbsview_Cleanup(void **ViewSpecific)
+{
+       struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
+       lprintf(9, "bbsview_Cleanup() has been called\n");
+       free(BBS);
+
+       if (WC->is_ajax) {
+               end_ajax_response();
+               WC->is_ajax = 0;
+       }
+       else {
+               wDumpContent(1);
+       }
+       return 0;
+}
+
+void 
+InitModule_BBSVIEWRENDERERS
+(void)
+{
+       RegisterReadLoopHandlerset(
+               VIEW_BBS,
+               bbsview_GetParamsGetServerCall,
+               bbsview_PrintViewHeader,
+               bbsview_LoadMsgFromServer,
+               bbsview_RenderView_or_Tail,
+               bbsview_Cleanup);
+}
+
+
+#endif /* NEW_BBS_VIEW */