7 /* We're jamming both of these in here so I can develop the new BBS view in-tree.
8 * Define NEW_BBS_BIEW to get the new, better, but unfinished and untested version.
15 /*** Code for the OLD bbs view ***/
18 typedef struct _bbsview_stuct {
19 StrBuf *BBViewToolBar;
20 StrBuf *MessageDropdown;
25 int bbsview_GetParamsGetServerCall(SharedMessageStatus *Stat,
33 VS = (bbsview_struct*) malloc(sizeof(bbsview_struct));
34 memset(VS, 0, sizeof(bbsview_struct));
35 *ViewSpecific = (void*)VS;
36 Stat->defaultsortorder = 1;
40 rlid[oper].cmd(cmd, len);
42 if (havebstr("maxmsgs"))
43 Stat->maxmsgs = ibstr("maxmsgs");
44 if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS;
46 if (havebstr("startmsg")) {
47 Stat->startmsg = lbstr("startmsg");
49 if (lbstr("SortOrder") == 2) {
51 Stat->num_displayed = -DEFAULT_MAXMSGS;
55 Stat->num_displayed = DEFAULT_MAXMSGS;
61 /* startmsg is an index within the message list.
62 * starting_from is the Citadel message number to be supplied to a "MSGS GT" operation
64 long DrawMessageDropdown(StrBuf *Selector, long maxmsgs, long startmsg, int nMessages, long starting_from)
76 WCTemplputParams SubTP;
79 memset(&SubTP, 0, sizeof(WCTemplputParams));
80 SubTP.Filter.ContextType = CTX_LONGVECTOR;
81 SubTP.Context = &vector;
82 TmpBuf = NewStrBufPlain(NULL, SIZ);
83 At = GetNewHashPos(WCC->summ, nMessages);
84 nItems = GetCount(WCC->summ);
90 vector[7] = starting_from;
95 vector[3] = abs(nMessages);
96 lo = GetHashPosCounter(WCC->summ, At);
97 wantmore = GetNextHashPos(WCC->summ, At, &hklen, &key, &vMsg);
101 if (lo + nMessages >= nItems) {
103 vector[3] = nItems - lo;
108 hi = lo + nMessages - 1;
111 if (lo + nMessages < -1) {
115 if ((lo % abs(nMessages)) != 0) {
116 int offset = (lo % abs(nMessages) *
117 (nMessages / abs(nMessages)));
119 vector[3] = abs(offset);
129 * Bump these because although we're thinking in zero base, the user
130 * is a drooling idiot and is thinking in one base.
136 dbg_print_longvector(vector);
137 DoTemplate(HKEY("select_messageindex"), TmpBuf, &SubTP);
138 StrBufAppendBuf(Selector, TmpBuf, 0);
142 if (maxmsgs == 9999999) {
149 dbg_print_longvector(vector);
150 DoTemplate(HKEY("select_messageindex_all"), TmpBuf, &SubTP);
151 StrBufAppendBuf(Selector, TmpBuf, 0);
158 int bbsview_PrintViewHeader(SharedMessageStatus *Stat, void **ViewSpecific)
161 WCTemplputParams SubTP;
163 VS = (bbsview_struct*)*ViewSpecific;
165 VS->BBViewToolBar = NewStrBufPlain(NULL, SIZ);
166 VS->MessageDropdown = NewStrBufPlain(NULL, SIZ);
168 /*** startmsg->maxmsgs = **/DrawMessageDropdown(VS->MessageDropdown,
172 Stat->lowest_found-1);
173 if (Stat->num_displayed < 0) {
174 Stat->startmsg += Stat->maxmsgs;
175 if (Stat->num_displayed != Stat->maxmsgs)
176 Stat->maxmsgs = abs(Stat->maxmsgs) + 1;
178 Stat->maxmsgs = abs(Stat->maxmsgs);
181 if (Stat->nummsgs > 0) {
182 memset(&SubTP, 0, sizeof(WCTemplputParams));
183 SubTP.Filter.ContextType = CTX_STRBUF;
184 SubTP.Context = VS->MessageDropdown;
185 DoTemplate(HKEY("msg_listselector_top"), VS->BBViewToolBar, &SubTP);
186 StrBufAppendBuf(WC->WBuf, VS->BBViewToolBar, 0);
187 FlushStrBuf(VS->BBViewToolBar);
192 int bbsview_LoadMsgFromServer(SharedMessageStatus *Stat,
194 message_summary* Msg,
200 VS = (bbsview_struct*)*ViewSpecific;
201 if (VS->displayed_msgs == NULL) {
202 VS->displayed_msgs = malloc(sizeof(long) *
203 ((Stat->maxmsgs < Stat->nummsgs) ?
207 if ((i >= Stat->startmsg) && (i < Stat->startmsg + Stat->maxmsgs)) {
208 VS->displayed_msgs[Stat->num_displayed] = Msg->msgnum;
209 Stat->num_displayed++;
215 int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat,
221 WCTemplputParams SubTP;
224 VS = (bbsview_struct*)*ViewSpecific;
225 if (Stat->nummsgs == 0) {
226 wc_printf("<div class=\"nomsgs\"><br><em>");
229 wc_printf(_("No new messages."));
232 wc_printf(_("No old messages."));
235 wc_printf(_("No messages here."));
237 wc_printf("</em><br></div>\n");
241 if (VS->displayed_msgs != NULL) {
242 /* if we do a split bbview in the future, begin messages div here */
244 for (a=0; a < Stat->num_displayed; ++a) {
245 read_message(WCC->WBuf, HKEY("view_message"), VS->displayed_msgs[a], NULL, &Mime);
248 /* if we do a split bbview in the future, end messages div here */
250 free(VS->displayed_msgs);
251 VS->displayed_msgs = NULL;
253 memset(&SubTP, 0, sizeof(WCTemplputParams));
254 SubTP.Filter.ContextType = CTX_STRBUF;
255 SubTP.Context = VS->MessageDropdown;
256 DoTemplate(HKEY("msg_listselector_bottom"), VS->BBViewToolBar, &SubTP);
257 StrBufAppendBuf(WCC->WBuf, VS->BBViewToolBar, 0);
264 int bbsview_Cleanup(void **ViewSpecific)
268 VS = (bbsview_struct*)*ViewSpecific;
270 FreeStrBuf(&VS->BBViewToolBar);
271 FreeStrBuf(&VS->MessageDropdown);
277 InitModule_BBSVIEWRENDERERS
280 RegisterReadLoopHandlerset(
282 bbsview_GetParamsGetServerCall,
283 bbsview_PrintViewHeader,
284 bbsview_LoadMsgFromServer,
285 bbsview_RenderView_or_Tail,
293 #else /* NEW_BBS_VIEW */
296 /*** Code for the NEW bbs view ***/
301 * Data which gets passed around between the various functions in this module
304 long *msgs; /* Array of msgnums for messages we are displaying */
305 int num_msgs; /* Number of msgnums stored in 'msgs' */
306 int alloc_msgs; /* Currently allocated size of array */
311 * Entry point for message read operations.
313 int bbsview_GetParamsGetServerCall(SharedMessageStatus *Stat,
319 struct bbsview *BBS = malloc(sizeof(struct bbsview));
320 memset(BBS, 0, sizeof(struct bbsview));
323 Stat->defaultsortorder = 1;
327 rlid[oper].cmd(cmd, len); /* this performs the server call to fetch the msg list */
329 if (havebstr("maxmsgs")) {
330 Stat->maxmsgs = ibstr("maxmsgs");
332 if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS;
334 if (havebstr("startmsg")) {
335 Stat->startmsg = lbstr("startmsg");
337 if (lbstr("SortOrder") == 2) {
339 Stat->num_displayed = -DEFAULT_MAXMSGS;
343 Stat->num_displayed = DEFAULT_MAXMSGS;
351 * begin_ajax_response() was moved from bbsview_LoadMsgFromServer() to here ...
353 int bbsview_PrintViewHeader(SharedMessageStatus *Stat, void **ViewSpecific)
355 lprintf(9, "bbsview_PrintViewHeader() has been called.\n");
358 begin_ajax_response(); /* for non-ajax, headers are output in messages.c */
366 * This function is called for every message in the list.
368 int bbsview_LoadMsgFromServer(SharedMessageStatus *Stat,
370 message_summary* Msg,
374 struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
376 lprintf(9, "bbsview_LoadMsgFromServer() has been called.\n");
378 if (BBS->num_msgs < Stat->maxmsgs) {
380 if (BBS->alloc_msgs == 0) {
381 BBS->alloc_msgs = Stat->maxmsgs;
382 BBS->msgs = malloc(BBS->alloc_msgs * sizeof(long));
385 /* Theoretically this never happens because the initial allocation == maxmsgs */
386 if (BBS->num_msgs >= BBS->alloc_msgs) {
387 BBS->alloc_msgs *= 2;
388 BBS->msgs = realloc(BBS->msgs, (BBS->alloc_msgs * sizeof(long)));
391 BBS->msgs[BBS->num_msgs++] = Msg->msgnum;
396 int bbsview_sortfunc_reverse(const void *s1, const void *s2) {
403 if (l1 > l2) return(-1);
404 if (l1 < l2) return(+1);
409 int bbsview_sortfunc_forward(const void *s1, const void *s2) {
416 if (l1 > l2) return(+1);
417 if (l1 < l2) return(-1);
422 int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat,
426 struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
431 lprintf(9, "starting bbsview_RenderView_or_Tail() - there are %d messages.\n", BBS->num_msgs);
433 /* Handle the empty message set gracefully... */
434 if (Stat->nummsgs == 0) {
436 wc_printf("<div class=\"nomsgs\"><br><em>");
437 wc_printf(_("No messages here."));
438 wc_printf("</em><br></div>\n");
442 /* Non-empty message set... */
444 lprintf(9, "sorting %d messages\n", BBS->num_msgs);
445 qsort(BBS->msgs, (size_t)(BBS->num_msgs), sizeof(long), (Stat->reverse ? bbsview_sortfunc_reverse : bbsview_sortfunc_forward));
447 for (i=0; i<BBS->num_msgs; ++i) {
448 read_message(WC->WBuf, HKEY("view_message"), BBS->msgs[i], NULL, &Mime);
453 snprintf(morediv, sizeof morediv, "morediv%08lx%08x", time(NULL), rand());
455 if (!WC->is_ajax) { /* only supply the script during the initial page load */
456 StrBufAppendPrintf(WC->trailing_javascript,
457 " function moremsgs(target_div, subcmd_name, subcmd_value, maxmsgs, sortorder) { \n"
458 " $(target_div).innerHTML = '<div class=\"moreprompt\">%s ... <img src=\"static/throbber.gif\"><br><br><br></div>'; \n"
459 " p = subcmd_name + '=' + subcmd_value + '&maxmsgs=' + maxmsgs \n"
460 " + '&is_summary=0&SortOrder=' + sortorder + '&is_ajax=1' \n"
461 " + '&r=' + CtdlRandomString(); \n"
462 " new Ajax.Updater(target_div, 'readgt', \n"
463 " { method: 'get', parameters: p, evalScripts: true } ); \n"
470 wc_printf("<div id=\"%s\">", morediv);
471 /* if (Stat->nummsgs > 0) { */
472 if (Stat->nummsgs >= Stat->maxmsgs) {
473 wc_printf("<a href=\"javascript:moremsgs('%s', 'gt', %ld, %ld, %d );\">",
475 BBS->msgs[BBS->num_msgs-1],
477 (Stat->reverse ? 2 : 1)
480 wc_printf("<div class=\"moreprompt\">"
481 "↓ ↓ ↓ %s ↓ ↓ ↓"
487 long gt = 0; /* if new messages appear later, where will they begin? */
488 if (Stat->nummsgs > 0) {
489 gt = BBS->msgs[BBS->num_msgs-1];
492 gt = atol(bstr("gt"));
494 wc_printf("<a href=\"javascript:moremsgs('%s', 'gt', %ld, %ld, %d );\">",
498 (Stat->reverse ? 2 : 1)
500 wc_printf("<div class=\"moreprompt\">");
501 wc_printf("no more ... gt would have been %ld ... FIXME", gt);
505 wc_printf("<br><br><br><br></div>");
511 int bbsview_Cleanup(void **ViewSpecific)
513 struct bbsview *BBS = (struct bbsview *) *ViewSpecific;
514 lprintf(9, "bbsview_Cleanup() has been called.\n");
518 lprintf(9, "end_ajax_response() has been called.\n");
523 lprintf(9, "wDumpContent() has been called.\n");
530 InitModule_BBSVIEWRENDERERS
533 RegisterReadLoopHandlerset(
535 bbsview_GetParamsGetServerCall,
536 bbsview_PrintViewHeader,
537 bbsview_LoadMsgFromServer,
538 bbsview_RenderView_or_Tail,
543 #endif /* NEW_BBS_VIEW */