X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fbbsview_renderer.c;h=03d70ef2bd44accfea1a6f4ecbcc372a6179fca6;hb=db0db1e6d7d2cd604d646fa515e2e28ca7f21b92;hp=0ae07c0ee5fd98b0c07eb62510b6e7fd1f807a84;hpb=737ff69908ed0a4bb2b810e6aefafc15bd0f78a0;p=citadel.git diff --git a/webcit/bbsview_renderer.c b/webcit/bbsview_renderer.c index 0ae07c0ee..03d70ef2b 100644 --- a/webcit/bbsview_renderer.c +++ b/webcit/bbsview_renderer.c @@ -1,39 +1,79 @@ /* - * $Id: $ - * * BBS View renderer module for WebCit * - * Copyright (c) 1996-2009 by the citadel.org team + * Note: we briefly had a dynamic UI for this. I thought it was cool, but + * it was not received well by the user community. If you want to play + * with it, go get commit dcf99fe61379b78436c387ea3f89ebfd4ffaf635 of + * bbsview_renderer.c and have fun. + * + * Copyright (c) 1996-2011 by the citadel.org team * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define RANGE 5 + #include "webcit.h" #include "webserver.h" #include "groupdav.h" /* * 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' */ + long lastseen; /* The number of the last seen message in this room */ int alloc_msgs; /* Currently allocated size of array */ + int requested_page; /* Which page number did the user request? */ + int num_pages; /* Total number of pages in this room */ + long start_reading_at; /* Start reading at the page containing this message */ }; +/* + * Attempt to determine the closest thing to the "last seen message number" using the + * results of the GTSN command + */ +long bbsview_get_last_seen(void) +{ + char buf[SIZ] = "0"; + + serv_puts("GTSN"); + serv_getln(buf, sizeof buf); + if (buf[0] == '2') { + char *colon_pos; + char *comma_pos; + + comma_pos = strchr(buf, ','); /* kill first comma and everything to its right */ + if (comma_pos) { + *comma_pos = 0; + } + + colon_pos = strchr(buf, ':'); /* kill first colon and everything to its left */ + if (colon_pos) { + strcpy(buf, ++colon_pos); + } + } + + return(atol(buf)); +} + + + /* * Entry point for message read operations. */ @@ -47,42 +87,43 @@ int bbsview_GetParamsGetServerCall(SharedMessageStatus *Stat, 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; + Stat->startmsg = (-1); /* not used here */ + Stat->sortit = 1; /* not used here */ + Stat->num_displayed = DEFAULT_MAXMSGS; /* not used here */ + BBS->requested_page = 0; + BBS->lastseen = bbsview_get_last_seen(); + BBS->start_reading_at = 0; + + /* By default, the requested page is the first one. */ + if (havebstr("start_reading_at")) { + BBS->start_reading_at = lbstr("start_reading_at"); + BBS->requested_page = (-4); } - return 200; -} + /* However, if we are asked to start with a specific message number, make sure + * we start on the page containing that message + */ + /* Or, if a specific page was requested, make sure we go there */ + else if (havebstr("page")) { + BBS->requested_page = ibstr("page"); + } -/* - * begin_ajax_response() was moved from bbsview_LoadMsgFromServer() to here ... - */ -int bbsview_PrintViewHeader(SharedMessageStatus *Stat, void **ViewSpecific) -{ - if (WC->is_ajax) { - begin_ajax_response(); /* for non-ajax, headers are output in messages.c */ + /* Otherwise, if this is a "read new" operation, make sure we start on the page + * containing the first new message + */ + else if (oper == 3) { + BBS->requested_page = (-3); } + if (havebstr("maxmsgs")) { + Stat->maxmsgs = ibstr("maxmsgs"); + } + if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS; + + /* perform a "read all" call to fetch the message list -- we'll cut it down later */ + rlid[2].cmd(cmd, len); + return 200; } @@ -99,14 +140,16 @@ int bbsview_LoadMsgFromServer(SharedMessageStatus *Stat, struct bbsview *BBS = (struct bbsview *) *ViewSpecific; if (BBS->alloc_msgs == 0) { - BBS->alloc_msgs = Stat->maxmsgs; + BBS->alloc_msgs = 1000; BBS->msgs = malloc(BBS->alloc_msgs * sizeof(long)); + memset(BBS->msgs, 0, (BBS->alloc_msgs * sizeof(long)) ); } - /* Theoretically this never happens because the initial allocation == maxmsgs */ + /* Check our buffer size */ if (BBS->num_msgs >= BBS->alloc_msgs) { BBS->alloc_msgs *= 2; BBS->msgs = realloc(BBS->msgs, (BBS->alloc_msgs * sizeof(long))); + memset(&BBS->msgs[BBS->num_msgs], 0, ((BBS->alloc_msgs - BBS->num_msgs) * sizeof(long)) ); } BBS->msgs[BBS->num_msgs++] = Msg->msgnum; @@ -114,20 +157,8 @@ int bbsview_LoadMsgFromServer(SharedMessageStatus *Stat, 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) { +int bbsview_sortfunc(const void *s1, const void *s2) { long l1; long l2; @@ -146,166 +177,217 @@ int bbsview_RenderView_or_Tail(SharedMessageStatus *Stat, { struct bbsview *BBS = (struct bbsview *) *ViewSpecific; int i; + int seq; const StrBuf *Mime; - char olderdiv[64]; - char newerdiv[64]; - int doing_older_messages = 0; - int doing_newer_messages = 0; - - snprintf(olderdiv, sizeof olderdiv, "olderdiv%08lx%08x", time(NULL), rand()); - snprintf(newerdiv, sizeof newerdiv, "newerdiv%08lx%08x", time(NULL), rand()); - - /* If this is the initial page load (and not an update), supply the required JavaScript code */ - if (!WC->is_ajax) { - StrBufAppendPrintf(WC->trailing_javascript, - " function moremsgs(target_div, gt_or_lt, gt_or_lt_value, maxmsgs, sortorder) { \n" - " $(target_div).innerHTML = '