]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* if we need the first urlpart, we musn't move it just left, but add another one...
[citadel.git] / webcit / messages.c
index 269d1da7945bb1a57480cdf058e1e92f16a4a695..2286a04217fca82b8bac9cf887d2fbc0b3dac3b0 100644 (file)
@@ -249,7 +249,7 @@ void embed_message(void) {
        long msgnum = 0L;
        const StrBuf *Tmpl = sbstr("template");
 
-       msgnum = StrTol(WC->UrlFragment1);
+       msgnum = StrTol(WC->UrlFragment2);
        if (StrLength(Tmpl) > 0) 
                read_message(WC->WBuf, SKEY(Tmpl), msgnum, 0, NULL);
        else 
@@ -265,7 +265,7 @@ void embed_message(void) {
 void print_message(void) {
        long msgnum = 0L;
 
-       msgnum = StrTol(WC->UrlFragment1);
+       msgnum = StrTol(WC->UrlFragment2);
        output_headers(0, 0, 0, 0, 0, 0);
 
        hprintf("Content-type: text/html\r\n"
@@ -286,7 +286,7 @@ void print_message(void) {
  */
 void mobile_message_view(void) {
   long msgnum = 0L;
-  msgnum = StrTol(WC->UrlFragment1);
+  msgnum = StrTol(WC->UrlFragment2);
   output_headers(1, 0, 0, 0, 0, 1);
   begin_burst();
   do_template("msgcontrols", NULL);
@@ -303,7 +303,7 @@ void display_headers(void) {
        long msgnum = 0L;
        char buf[1024];
 
-       msgnum = StrTol(WC->UrlFragment1);
+       msgnum = StrTol(WC->UrlFragment2);
        output_headers(0, 0, 0, 0, 0, 0);
 
        hprintf("Content-type: text/plain\r\n"
@@ -938,16 +938,20 @@ int load_msg_ptrs(char *servcmd, int with_headers)
 
 inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
 {
+       const char *Key;
+       long HKLen;
        void *vMsg;
+
        if (Summ == NULL)
                return NULL;
-       GetHash(Summ, (const char*)&n, sizeof(n), &vMsg);
+       GetHashAt(Summ, n, &HKLen, &Key, &vMsg);
        return (message_summary*) vMsg;
 }
 
 
-void DrawMessageSummarySelector(StrBuf *BBViewToolBar, long maxmsgs, long startmsg)
+void DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg)
 {
+       StrBuf *TmpBuf;
        struct wcsession *WCC = WC;
        message_summary* Msg;
        int lo, hi, n;
@@ -960,9 +964,10 @@ void DrawMessageSummarySelector(StrBuf *BBViewToolBar, long maxmsgs, long startm
        int nItems;
        HashPos *At;
        long vector[16];
-       StrBuf *Selector = NewStrBuf();
+       int nMessages = DEFAULT_MAXMSGS;
 
-       At = GetNewHashPos(WCC->summ, (lbstr("SortOrder") == 1)? -maxmsgs : maxmsgs);
+       TmpBuf = NewStrBuf();
+       At = GetNewHashPos(WCC->summ, (lbstr("SortOrder") == 1)? -nMessages : nMessages);
        nItems = GetCount(WCC->summ);
        
        vector[0] = 7;
@@ -973,11 +978,11 @@ void DrawMessageSummarySelector(StrBuf *BBViewToolBar, long maxmsgs, long startm
 
        while (!done) {
                lo = GetHashPosCounter(At);
-               if (lo + maxmsgs > nItems) {
+               if (lo + nMessages > nItems) {
                        hi = nItems;
                }
                else {
-                       hi = lo + maxmsgs;
+                       hi = lo + nMessages;
                }
                done = !GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
                Msg = (message_summary*) vMsg;
@@ -987,29 +992,30 @@ void DrawMessageSummarySelector(StrBuf *BBViewToolBar, long maxmsgs, long startm
                vector[4] = lo;
                vector[5] = hi;
                vector[6] = n;
-               FlushStrBuf(BBViewToolBar); /** abuse our target buffer to contstruct one item in it */
-               DoTemplate(HKEY("select_messageindex"), BBViewToolBar, &vector, CTX_LONGVECTOR);
-               StrBufAppendBuf(Selector, BBViewToolBar, 0);
+               FlushStrBuf(TmpBuf);
+               DoTemplate(HKEY("select_messageindex"), TmpBuf, &vector, CTX_LONGVECTOR);
+               StrBufAppendBuf(Selector, TmpBuf, 0);
                i++;
        }
        vector[6] = StartMsg;
-       FlushStrBuf(BBViewToolBar);
-       DoTemplate(HKEY("select_messageindex_all"), BBViewToolBar, &vector, CTX_LONGVECTOR);
-       StrBufAppendBuf(Selector, BBViewToolBar, 0);
-       
-       FlushStrBuf(BBViewToolBar);
-       DoTemplate(HKEY("msg_listselector"), BBViewToolBar, Selector, CTX_STRBUF);
-       FreeStrBuf(&Selector);
+       FlushStrBuf(TmpBuf);
+       DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &vector, CTX_LONGVECTOR);
+       StrBufAppendBuf(Selector, TmpBuf, 0);
+       FreeStrBuf(&TmpBuf);
+       DeleteHashPos(&At);
 }
 
 
+extern readloop_struct rlid[];
+
 /*
  * command loop for reading messages
  *
  * Set oper to "readnew" or "readold" or "readfwd" or "headers"
  */
-void readloop(char *oper)
+void readloop(long oper)
 {
+       StrBuf *MessageDropdown = NULL;
        StrBuf *BBViewToolBar = NULL;
        void *vMsg;
        message_summary *Msg;
@@ -1020,7 +1026,7 @@ void readloop(char *oper)
        ///int b = 0;
        int nummsgs;
        long startmsg = 0;
-       int maxmsgs;
+       int maxmsgs = 0;
        long *displayed_msgs = NULL;
        int num_displayed = 0;
        int is_summary = 0;
@@ -1071,7 +1077,7 @@ void readloop(char *oper)
                is_singlecard = ibstr("is_singlecard");
                if (maxmsgs > 1) {
                        is_addressbook = 1;
-                       if (!strcmp(oper, "do_search")) {
+                       if (oper == do_search) {
                                snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
                        }
                        else {
@@ -1095,25 +1101,11 @@ void readloop(char *oper)
                 * When in summary mode, always show ALL messages instead of just
                 * new or old.  Otherwise, show what the user asked for.
                 */
-               if (!strcmp(oper, "readnew")) {
-                       strcpy(cmd, "MSGS NEW");
-               }
-               else if (!strcmp(oper, "readold")) {
-                       strcpy(cmd, "MSGS OLD");
-               }
-               else if (!strcmp(oper, "do_search")) {
-                       snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
-               }
-               else {
-                       strcpy(cmd, "MSGS ALL");
-               }
+               rlid[oper].cmd(cmd, sizeof(cmd));
                
                if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
                        is_summary = 1;
-                       if (!strcmp(oper, "do_search")) {
-                               snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
-                       }
-                       else {
+                       if (oper != do_search) {
                                strcpy(cmd, "MSGS ALL");
                        }
                }
@@ -1122,13 +1114,16 @@ void readloop(char *oper)
                if (is_summary) {                       /**< fetch header summary */
                        load_seen = 1;
                        snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
-                                (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
-                                (!strcmp(oper, "do_search") ? bstr("query") : "")
+                                (oper == do_search) ? "SEARCH" : "ALL",
+                                (oper == do_search) ? bstr("query") : ""
                                );
                        startmsg = 1;
                        maxmsgs = 9999999;
                } 
-               if (startmsg == 0L) {
+
+               bbs_reverse = is_bbview && (lbstr("SortOrder") == 2);
+
+               if (is_bbview && (startmsg == 0L)) {
                        if (bbs_reverse) {
                                Msg = GetMessagePtrAt((nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0, WCC->summ);
                                startmsg = (Msg==NULL)? 0 : Msg->msgnum;
@@ -1165,11 +1160,14 @@ void readloop(char *oper)
        if (nummsgs == 0) {
                if (care_for_empty_list) {
                        wprintf("<div align=\"center\"><br /><em>");
-                       if (!strcmp(oper, "readnew")) {
+                       switch (oper) {
+                       case readnew:
                                wprintf(_("No new messages."));
-                       } else if (!strcmp(oper, "readold")) {
+                               break;
+                       case readold:
                                wprintf(_("No old messages."));
-                       } else {
+                               break;
+                       default:
                                wprintf(_("No messages here."));
                        }
                        wprintf("</em><br /></div>\n");
@@ -1222,10 +1220,13 @@ void readloop(char *oper)
         */
        if (is_bbview)  {
                BBViewToolBar = NewStrBuf();
-               maxmsgs = 20; //// todo?
+               MessageDropdown = NewStrBuf();
 
-               DrawMessageSummarySelector(BBViewToolBar, maxmsgs, startmsg);
+               DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg);
+               
+               DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, MessageDropdown, CTX_STRBUF);
                StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
+               FlushStrBuf(BBViewToolBar);
        }
                        
        at = GetNewHashPos(WCC->summ, 0);
@@ -1292,18 +1293,7 @@ void readloop(char *oper)
        }
 
        if (is_summary) {
-               wprintf("</table>"
-                       "</div>\n");                    /**< end of 'fix_scrollbar_bug' div */
-               wprintf("</div>");                      /**< end of 'message_list' div */
-               
-               /** Here's the grab-it-to-resize-the-message-list widget */
-               wprintf("<div id=\"resize_msglist\" "
-                       "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
-                       "<div class=\"fix_scrollbar_bug\"> <hr>"
-                       "</div></div>\n"
-               );
-
-               wprintf("<div id=\"preview_pane\">");   /**< The preview pane will initially be empty */
+               do_template("summary_trailer", NULL);
        } else if (WCC->is_mobile) {
                wprintf("</div>");
        }
@@ -1321,7 +1311,12 @@ void readloop(char *oper)
         */
        if (is_bbview) {
                /** begin bbview scroller */
+
+               DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, MessageDropdown, CTX_STRBUF);
                StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
+
+               FreeStrBuf(&BBViewToolBar);
+               FreeStrBuf(&MessageDropdown);
        }
        
 DONE:
@@ -1640,7 +1635,7 @@ void post_message(void)
         *  Otherwise, just go to the "read messages" loop.
         */
        else {
-               readloop("readnew");
+               readloop(readnew);
        }
 }
 
@@ -1684,7 +1679,7 @@ void display_enter(void)
        }
        else if (buf[0] != '2') {               /** Any other error means that we cannot continue */
                sprintf(WCC->ImportantMessage, "%s", &buf[4]);
-               readloop("readnew");
+               readloop(readnew);
                return;
        }
 
@@ -1801,7 +1796,7 @@ void delete_msg(void)
        serv_getln(buf, sizeof buf);
        sprintf(WC->ImportantMessage, "%s", &buf[4]);
 
-       readloop("readnew");
+       readloop(readnew);
 }
 
 
@@ -1824,7 +1819,7 @@ void move_msg(void)
                sprintf(WC->ImportantMessage, (_("The message was not moved.")));
        }
 
-       readloop("readnew");
+       readloop(readnew);
 }
 
 
@@ -1884,11 +1879,11 @@ void confirm_move_msg(void)
        wDumpContent(1);
 }
 
-void readnew(void) { readloop("readnew");}
-void readold(void) { readloop("readold");}
-void readfwd(void) { readloop("readfwd");}
-void headers(void) { readloop("headers");}
-void do_search(void) { readloop("do_search");}
+void h_readnew(void) { readloop(readnew);}
+void h_readold(void) { readloop(readold);}
+void h_readfwd(void) { readloop(readfwd);}
+void h_headers(void) { readloop(headers);}
+void h_do_search(void) { readloop(do_search);}
 
 
 
@@ -1899,11 +1894,11 @@ void
 InitModule_MSG
 (void)
 {
-       WebcitAddUrlHandler(HKEY("readnew"), readnew, NEED_URL);
-       WebcitAddUrlHandler(HKEY("readold"), readold, NEED_URL);
-       WebcitAddUrlHandler(HKEY("readfwd"), readfwd, NEED_URL);
-       WebcitAddUrlHandler(HKEY("headers"), headers, NEED_URL);
-       WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
+       WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
+       WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
+       WebcitAddUrlHandler(HKEY("readfwd"), h_readfwd, NEED_URL);
+       WebcitAddUrlHandler(HKEY("headers"), h_headers, NEED_URL);
+       WebcitAddUrlHandler(HKEY("do_search"), h_do_search, 0);
        WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
        WebcitAddUrlHandler(HKEY("post"), post_message, 0);
        WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);