]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* fix dropdown
[citadel.git] / webcit / messages.c
index 9103e290d5b5ef50941ce8faa42ecc2812496e1d..3291e45ac3fc4a0f9c9219e6865fc2b39936e3e5 100644 (file)
@@ -440,7 +440,7 @@ int load_msg_ptrs(char *servcmd, int with_headers)
                        Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
                        StrBufExtract_token(Buf2,  Buf, 5, '|');
                        if (StrLength(Buf2) == 0)
-                               StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
+                               StrBufAppendBufPlain(Msg->subj, _("(no subj)"), -1,0);
                        else {
                                StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
                                if ((StrLength(Msg->subj) > 75) && 
@@ -480,7 +480,7 @@ inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
 }
 
 
-void DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg)
+long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg)
 {
        StrBuf *TmpBuf;
        wcsession *WCC = WC;
@@ -488,6 +488,7 @@ void DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg)
        int lo, hi, n;
        int i = 0;
        long StartMsg = 0;
+       long ret;
        void *vMsg;
        long hklen;
        const char *key;
@@ -495,12 +496,12 @@ void DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg)
        int nItems;
        HashPos *At;
        long vector[16];
-       int nMessages = DEFAULT_MAXMSGS;
+       int nMessages = (lbstr("SortOrder") == 1)? DEFAULT_MAXMSGS : -DEFAULT_MAXMSGS;
 
        TmpBuf = NewStrBuf();
-       At = GetNewHashPos(WCC->summ, (lbstr("SortOrder") == 1)? -nMessages : nMessages);
+       At = GetNewHashPos(WCC->summ, nMessages);
        nItems = GetCount(WCC->summ);
-       
+       ret = abs(nMessages);
        vector[0] = 7;
        vector[1] = startmsg;
        vector[2] = maxmsgs;
@@ -509,33 +510,87 @@ void DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg)
 
        while (!done) {
                lo = GetHashPosCounter(At);
-               if (lo + nMessages > nItems) {
-                       hi = nItems;
-               }
-               else {
-                       hi = lo + nMessages;
+               if (nMessages > 0) {
+                       if (lo + nMessages > nItems) {
+                               hi = nItems;
+                       }
+                       else {
+                               hi = lo + nMessages;
+                       }
+               } else {
+                       if (lo + nMessages <= 0) {
+                               hi = 1;
+                       }
+                       else {
+                               if (lo % abs(nMessages) != 0)
+                                       hi = lo + (lo % abs(nMessages) *
+                                                   (nMessages / abs(nMessages)));
+                               else
+                                       hi = lo + nMessages;
+                       }
                }
                done = !GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
                Msg = (message_summary*) vMsg;
                n = (Msg==NULL)? 0 : Msg->msgnum;
                if (i == 0)
                        StartMsg = n;
-               vector[4] = lo;
+               if ((vector[1] == n) && (lo - hi + 1 != nMessages)) {
+                       ret = abs(lo - hi + 1);
+               }
+               vector[4] = lo + 1;
                vector[5] = hi;
                vector[6] = n;
                FlushStrBuf(TmpBuf);
+               dbg_print_longvector(vector);
                DoTemplate(HKEY("select_messageindex"), TmpBuf, &vector, CTX_LONGVECTOR);
                StrBufAppendBuf(Selector, TmpBuf, 0);
                i++;
        }
        vector[6] = StartMsg;
        FlushStrBuf(TmpBuf);
+       vector[1] = lbstr("maxmsgs") == 9999999;
+       vector[2] = 0;
+       dbg_print_longvector(vector);
        DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &vector, CTX_LONGVECTOR);
        StrBufAppendBuf(Selector, TmpBuf, 0);
        FreeStrBuf(&TmpBuf);
        DeleteHashPos(&At);
+       return ret;
 }
 
+void load_seen_flags(void)
+{
+       message_summary *Msg;
+       const char *HashKey;
+       long HKLen;
+       StrBuf *OldMsg = NewStrBuf();;
+       wcsession *WCC = WC;
+       HashPos *at;
+       void *vMsg;
+
+       serv_puts("GTSN");
+       StrBuf_ServGetln(OldMsg);
+       if (ChrPtr(OldMsg)[0] == '2') {
+               StrBufCutLeft(OldMsg, 4);
+       }
+       else {
+               FreeStrBuf(&OldMsg);
+               return;
+       }
+       at = GetNewHashPos(WCC->summ, 0);
+       while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
+               /** Are you a new message, or an old message? */
+               Msg = (message_summary*) vMsg;
+               if (is_msg_in_mset(ChrPtr(OldMsg), Msg->msgnum)) {
+                       Msg->is_new = 0;
+               }
+               else {
+                       Msg->is_new = 1;
+               }
+       }
+       FreeStrBuf(&OldMsg);
+       DeleteHashPos(&at);
+}
 
 extern readloop_struct rlid[];
 
@@ -552,7 +607,6 @@ void readloop(long oper)
        message_summary *Msg;
        char cmd[256] = "";
        char buf[SIZ];
-       char old_msgs[SIZ];
        int a = 0;
        int nummsgs;
        long startmsg = 0;
@@ -560,12 +614,9 @@ void readloop(long oper)
        long *displayed_msgs = NULL;
        int num_displayed = 0;
        int is_summary = 0;
-       int is_addressbook = 0;
        int is_singlecard = 0;
-       int is_calendar = 0;
        struct calview calv;
-       int is_tasks = 0;
-       int is_notes = 0;
+
        int is_bbview = 0;
        int lowest_displayed = (-1);
        int highest_displayed = 0;
@@ -587,26 +638,22 @@ void readloop(long oper)
                return;
        case VIEW_CALENDAR:
                load_seen = 1;
-               is_calendar = 1;
                strcpy(cmd, "MSGS ALL|||1");
                maxmsgs = 32767;
                parse_calendar_view_request(&calv);
                break;
        case VIEW_TASKS:
-               is_tasks = 1;
                strcpy(cmd, "MSGS ALL");
                maxmsgs = 32767;
                break;
        case VIEW_NOTES:
-               is_notes = 1;
                strcpy(cmd, "MSGS ALL");
                maxmsgs = 32767;
                wprintf("<div id=\"new_notes_here\"></div>\n");
                break;
        case VIEW_ADDRESSBOOK:
                is_singlecard = ibstr("is_singlecard");
-               if (maxmsgs > 1) {
-                       is_addressbook = 1;
+               if (is_singlecard != 1) {
                        if (oper == do_search) {
                                snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
                        }
@@ -616,7 +663,7 @@ void readloop(long oper)
                        maxmsgs = 9999999;
                        break;
                }
-
+               break;
        default:
                care_for_empty_list = 1;
                startmsg = lbstr("startmsg");
@@ -651,29 +698,30 @@ void readloop(long oper)
                        maxmsgs = 9999999;
                } 
 
-               bbs_reverse = is_bbview && (lbstr("SortOrder") == 2);
-
+               if (is_bbview) {
+                       SetAccessCommand(oper);
+                       if (havebstr("SortOrder")) {
+                               bbs_reverse = lbstr("SortOrder") == 2;
+                       }
+                       else {
+                               StrBuf *Buf = NewStrBufPlain(HKEY("1"));
+                               putbstr("SortOrder", Buf);
+                               Buf = NewStrBufPlain(HKEY("date"));
+                               putbstr("SortBy", Buf);
+                               bbs_reverse = 0;
+                       }
+               }
                sortit = is_summary || WCC->is_mobile;
+               if (WCC->is_mobile) {
+                       maxmsgs = 20;
+                       snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
+                                ((oper == do_search) ? "SEARCH" : "ALL"),
+                                ((oper == do_search) ? bstr("query") : "")
+                               );
+               }
        }
-
-
        output_headers(1, 1, 1, 0, 0, 0);
 
-       /* TODO: how can we best sort this in?
-       if (WCC->is_mobile) {
-               maxmsgs = 20;
-               snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
-                       (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
-                       (!strcmp(oper, "do_search") ? bstr("query") : "")
-               );
-               SortBy =  eRDate;
-       }
-       */
-       /*
-        * Are we doing a summary view?  If so, we need to know old messages
-        * and new messages, so we can do that pretty boldface thing for the
-        * new messages.
-        */
        nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
        if (nummsgs == 0) {
                if (care_for_empty_list) {
@@ -693,40 +741,6 @@ void readloop(long oper)
 
                goto DONE;
        }
-       if (is_bbview && (startmsg == 0L)) {
-               if (bbs_reverse) {
-                       Msg = GetMessagePtrAt((nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0, WCC->summ);
-                       startmsg = (Msg==NULL)? 0 : Msg->msgnum;
-               }
-               else {
-                       Msg = GetMessagePtrAt(0, WCC->summ);
-                       startmsg = (Msg==NULL)? 0 : Msg->msgnum;
-               }
-       }
-
-       /* This is done to make it run faster; WC is a function */
-       if (load_seen){
-               void *vMsg;
-
-               strcpy(old_msgs, "");
-               serv_puts("GTSN");
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '2') {
-                       strcpy(old_msgs, &buf[4]);
-               }
-               at = GetNewHashPos(WCC->summ, 0);
-               while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
-                       /** Are you a new message, or an old message? */
-                       Msg = (message_summary*) vMsg;
-                       if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
-                               Msg->is_new = 0;
-                       }
-                       else {
-                               Msg->is_new = 1;
-                       }
-               }
-               DeleteHashPos(&at);
-       }
 
        if (sortit) {
                CompareFunc SortIt;
@@ -736,14 +750,22 @@ void readloop(long oper)
                        SortByPayload(WCC->summ, SortIt);
        }
 
-       if (is_summary) {
-               do_template("summary_header", NULL);
-       } else if (WCC->is_mobile) {
-               wprintf("<div id=\"message_list\">");
+       if (is_bbview && (startmsg == 0L)) {
+               if (bbs_reverse) {
+                       Msg = GetMessagePtrAt((nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0, WCC->summ);
+                       startmsg = (Msg==NULL)? 0 : Msg->msgnum;
+               }
+               else {
+                       Msg = GetMessagePtrAt(0, WCC->summ);
+                       startmsg = (Msg==NULL)? 0 : Msg->msgnum;
+               }
        }
 
+       if (load_seen) load_seen_flags();
+       if (is_summary) do_template("summary_header", NULL);
+       
 
-       /**
+        /**
         * If we're not currently looking at ALL requested
         * messages, then display the selector bar
         */
@@ -751,7 +773,7 @@ void readloop(long oper)
                BBViewToolBar = NewStrBuf();
                MessageDropdown = NewStrBuf();
 
-               DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg);
+               maxmsgs = DrawMessageDropdown(MessageDropdown, maxmsgs, startmsg);
                
                DoTemplate(HKEY("msg_listselector_top"), BBViewToolBar, MessageDropdown, CTX_STRBUF);
                StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
@@ -761,13 +783,20 @@ void readloop(long oper)
        at = GetNewHashPos(WCC->summ, 0);
        while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
                Msg = (message_summary*) vMsg;          
-               if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
-                               
-                       /** Display the message */
-                       if (is_summary) {
-                               DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
-                       }
-                       else if (is_addressbook) {
+               if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {                   
+                       switch (WCC->wc_view) {
+                       case VIEW_WIKI:
+                               break;
+                       case VIEW_CALENDAR:
+                               load_calendar_item(Msg, Msg->is_new, &calv);
+                               break;
+                       case VIEW_TASKS:
+                               display_task(Msg, Msg->is_new);
+                               break;
+                       case VIEW_NOTES:
+                               display_note(Msg, Msg->is_new);
+                               break;
+                       case VIEW_ADDRESSBOOK:
                                fetch_ab_name(Msg, buf);
                                ++num_ab;
                                addrbook = realloc(addrbook,
@@ -775,30 +804,25 @@ void readloop(long oper)
                                safestrncpy(addrbook[num_ab-1].ab_name, buf,
                                            sizeof(addrbook[num_ab-1].ab_name));
                                addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
-                       }
-                       else if (is_calendar) {
-                               load_calendar_item(Msg, Msg->is_new, &calv);
-                       }
-                       else if (is_tasks) {
-                               display_task(Msg, Msg->is_new);
-                       }
-                       else if (is_notes) {
-                               display_note(Msg, Msg->is_new);
-                       } else if (WCC->is_mobile) {
-                               DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
-                       }
-                       else {
-                               if (displayed_msgs == NULL) {
-                                       displayed_msgs = malloc(sizeof(long) *
-                                                               (maxmsgs<nummsgs ? maxmsgs : nummsgs));
+                               break;
+                       default:
+                               /** Display the message */
+                               if (is_summary) {
+                                       DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
+                               }
+                               else {
+                                       if (displayed_msgs == NULL) {
+                                               displayed_msgs = malloc(sizeof(long) *
+                                                                       (maxmsgs<nummsgs ? maxmsgs : nummsgs));
+                                       }
+                                       displayed_msgs[num_displayed] = Msg->msgnum;
                                }
-                               displayed_msgs[num_displayed] = Msg->msgnum;
-                       }
                        
-                       if (lowest_displayed < 0) lowest_displayed = a;
-                       highest_displayed = a;
+                               if (lowest_displayed < 0) lowest_displayed = a;
+                               highest_displayed = a;
                        
-                       ++num_displayed;
+                               num_displayed++;
+                       }
                }
        }
        DeleteHashPos(&at);
@@ -812,7 +836,7 @@ void readloop(long oper)
                /** if we do a split bbview in the future, begin messages div here */
 
                for (a=0; a<num_displayed; ++a) {
-                       read_message(WC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
+                       read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
                }
 
                /** if we do a split bbview in the future, end messages div here */
@@ -823,8 +847,6 @@ void readloop(long oper)
 
        if (is_summary) {
                do_template("summary_trailer", NULL);
-       } else if (WCC->is_mobile) {
-               wprintf("</div>");
        }
 
        /**
@@ -839,8 +861,6 @@ void readloop(long oper)
         * messages, then display the selector bar
         */
        if (is_bbview) {
-               /** begin bbview scroller */
-
                DoTemplate(HKEY("msg_listselector_bottom"), BBViewToolBar, MessageDropdown, CTX_STRBUF);
                StrBufAppendBuf(WCC->WBuf, BBViewToolBar, 0);
 
@@ -849,18 +869,23 @@ void readloop(long oper)
        }
        
 DONE:
-       if (is_tasks) {
-               do_tasks_view();        /** Render the task list */
-       }
-
-       if (is_calendar) {
+       switch (WCC->wc_view) {
+       case VIEW_WIKI:
+               break;
+       case VIEW_CALENDAR:
                render_calendar_view(&calv);
-       }
-
-       if (is_addressbook) {
+               break;
+       case VIEW_TASKS:
+               do_tasks_view();        /** Render the task list */
+               break;
+       case VIEW_NOTES:
+               break;
+       case VIEW_ADDRESSBOOK:
                do_addrbook_view(addrbook, num_ab);     /** Render the address book */
+               break;
+       default:
+               break;
        }
-
        /** Note: wDumpContent() will output one additional </div> tag. */
        wprintf("</div>\n");            /** end of 'content' div */
        wDumpContent(1);
@@ -1564,19 +1589,12 @@ void download_postpart(void) {
                 1);
 }
 
-
-
 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);}
 
-
-
-
-
-
 void 
 InitModule_MSG
 (void)