From a2e2b0eab5e29c1bd61ec21737d28d3cb70ee364 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 30 Jan 2018 00:20:32 -0500 Subject: [PATCH] initial work on flat view --- webcit-ng/Makefile | 2 +- webcit-ng/{threaded_view.c => forum_view.c} | 52 ++++++++++++++++++--- webcit-ng/room_functions.c | 7 ++- webcit-ng/static/index.html | 4 +- webcit-ng/static/js/views.js | 9 ++-- webcit-ng/webcit.h | 1 + 6 files changed, 60 insertions(+), 15 deletions(-) rename webcit-ng/{threaded_view.c => forum_view.c} (87%) diff --git a/webcit-ng/Makefile b/webcit-ng/Makefile index d1519e0a7..4182603c1 100644 --- a/webcit-ng/Makefile +++ b/webcit-ng/Makefile @@ -1,4 +1,4 @@ -OBJS := http.o main.o request.o ssl.o static.o tcp_sockets.o webserver.o ctdlclient.o admin_functions.o room_functions.o util.o caldav_reports.o messages.o ctdlfunctions.o ctdl_commands.o threaded_view.o html2html.o text2html.o +OBJS := http.o main.o request.o ssl.o static.o tcp_sockets.o webserver.o ctdlclient.o admin_functions.o room_functions.o util.o caldav_reports.o messages.o ctdlfunctions.o ctdl_commands.o forum_view.o html2html.o text2html.o CFLAGS := -ggdb LDFLAGS := diff --git a/webcit-ng/threaded_view.c b/webcit-ng/forum_view.c similarity index 87% rename from webcit-ng/threaded_view.c rename to webcit-ng/forum_view.c index d3e001b4e..995a6e187 100644 --- a/webcit-ng/threaded_view.c +++ b/webcit-ng/forum_view.c @@ -1,5 +1,5 @@ /* - * Threaded message view + * Forum view (threaded/flat) * * Copyright (c) 1996-2018 by the citadel.org team * @@ -27,7 +27,7 @@ struct mthread { // Renderer for one message in the threaded view // (This will probably work for the flat view too.) // -void thread_render_one_message(struct ctdlsession *c, StrBuf *sj, long msgnum) +void forum_render_one_message(struct ctdlsession *c, StrBuf *sj, long msgnum) { StrBuf *raw_msg = NULL; StrBuf *sanitized_msg = NULL; @@ -131,6 +131,19 @@ void thread_render_one_message(struct ctdlsession *c, StrBuf *sj, long msgnum) } +// Commands we need to send to Citadel Server before we begin rendering forum view. +// These are common to flat and threaded views. +// +void setup_for_forum_view(struct ctdlsession *c) +{ + char buf[1024]; + ctdl_printf(c, "MSGP text/html|text/plain"); // Declare the MIME types we know how to render + ctdl_readline(c, buf, sizeof(buf)); // Ignore the response + ctdl_printf(c, "MSGP dont_decode"); // Tell the server we will decode base64/etc client-side + ctdl_readline(c, buf, sizeof(buf)); // Ignore the response +} + + // Threaded view (recursive section) // void thread_o_print(struct ctdlsession *c, StrBuf *sj, struct mthread *m, int num_msgs, int where_parent_is, int nesting_level) @@ -147,7 +160,7 @@ void thread_o_print(struct ctdlsession *c, StrBuf *sj, struct mthread *m, int nu } StrBufAppendPrintf(sj, "
  • ", m[i].msgnum); - thread_render_one_message(c, sj, m[i].msgnum); + forum_render_one_message(c, sj, m[i].msgnum); StrBufAppendPrintf(sj, "
  • \r\n"); if (i != 0) { thread_o_print(c, sj, m, num_msgs, i, nesting_level+1); @@ -231,10 +244,7 @@ void threaded_view(struct http_transaction *h, struct ctdlsession *c, char *whic } // Now render it - ctdl_printf(c, "MSGP text/html|text/plain"); // Declare the MIME types we know how to render - ctdl_readline(c, buf, sizeof(buf)); // Ignore the response - ctdl_printf(c, "MSGP dont_decode"); // Tell the server we will decode base64/etc client-side - ctdl_readline(c, buf, sizeof(buf)); // Ignore the response + setup_for_forum_view(c); thread_o_print(c, sj, m, num_msgs, 0, 0); // Render threads recursively and recursively // Garbage collection is for people who aren't smart enough to manage their own memory. @@ -251,3 +261,31 @@ void threaded_view(struct http_transaction *h, struct ctdlsession *c, char *whic h->response_body = SmashStrBuf(&sj); return; } + + +// flat view (entry point) +// +void flat_view(struct http_transaction *h, struct ctdlsession *c, char *which) +{ + StrBuf *sj = NewStrBuf(); + StrBufAppendPrintf(sj, "\r\n"); + + setup_for_forum_view(c); + long *msglist = get_msglist(c, "ALL"); + if (msglist) { + int i; + for (i=0; (msglist[i] > 0); ++i) { + forum_render_one_message(c, sj, msglist[i]); + } + free(msglist); + } + + StrBufAppendPrintf(sj, "\r\n"); + + add_response_header(h, strdup("Content-type"), strdup("text/html; charset=utf-8")); + h->response_code = 200; + h->response_string = strdup("OK"); + h->response_body_length = StrLength(sj); + h->response_body = SmashStrBuf(&sj); + return; +} diff --git a/webcit-ng/room_functions.c b/webcit-ng/room_functions.c index dc4551ae5..f49485d47 100644 --- a/webcit-ng/room_functions.c +++ b/webcit-ng/room_functions.c @@ -136,6 +136,11 @@ void object_in_room(struct http_transaction *h, struct ctdlsession *c) return; } + if (!strncasecmp(buf, "flat", 5)) { // Client is requesting a flat view (still kind of fuzzy here) + flat_view(h, c, &buf[5]); + return; + } + if ( (c->room_default_view == VIEW_CALENDAR) // room types where objects are referenced by EUID || (c->room_default_view == VIEW_TASKS) || (c->room_default_view == VIEW_ADDRESSBOOK) @@ -382,7 +387,7 @@ void propfind_the_room_itself(struct http_transaction *h, struct ctdlsession *c) StrBufAppendPrintf(Buf, ""); free(datestring); } - if (enumerate_by_euid) { // FIXME ajc 2017oct30 should this really be inside the timestamp conditional? + if (enumerate_by_euid) { // FIXME ajc 2017oct30 should this be inside the timestamp conditional? StrBufAppendPrintf(Buf, "\"%ld\"", msglist[i]); } } diff --git a/webcit-ng/static/index.html b/webcit-ng/static/index.html index f7f4839ad..64f61512d 100644 --- a/webcit-ng/static/index.html +++ b/webcit-ng/static/index.html @@ -12,11 +12,11 @@ - + diff --git a/webcit-ng/static/js/views.js b/webcit-ng/static/js/views.js index 33da43667..3df884315 100644 --- a/webcit-ng/static/js/views.js +++ b/webcit-ng/static/js/views.js @@ -37,7 +37,7 @@ function render_room_view() { switch(current_view) { case views.VIEW_MAILBOX: // FIXME view mail rooms as forums for now case views.VIEW_BBS: - threads_readmessages(); + forum_readmessages("flat"); break; default: document.getElementById("main").innerHTML = "The view for " + current_room + " is " + current_view + " but there is no renderer." ; @@ -47,15 +47,16 @@ function render_room_view() { } -// bbs "threads" view +// Forum view -- flat or threaded // The inner div exists so that if the user clicks away early, the main div doesn't get clobbered when the load completes. +// The parameter can be set to "flat" or "threads" which is passed directly to the API // -function threads_readmessages() { +function forum_readmessages(flat_or_threads) { var innerdivname = randomString(5); document.getElementById("main").innerHTML = "
    " + _("Loading messages from server, please wait") + "
    " ; var request = new XMLHttpRequest(); - request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + "threads", true); + request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + flat_or_threads, true); request.onreadystatechange = function() { if (this.readyState === 4) { if ((this.status / 100) == 2) { diff --git a/webcit-ng/webcit.h b/webcit-ng/webcit.h index 8dfcf7116..72e40eed8 100644 --- a/webcit-ng/webcit.h +++ b/webcit-ng/webcit.h @@ -147,6 +147,7 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu ssize_t ctdl_write(struct ctdlsession *ctdl, const void *buf, size_t count); int login_to_citadel(struct ctdlsession *c, char *auth, char *resultbuf); void threaded_view(struct http_transaction *h, struct ctdlsession *c, char *which); +void flat_view(struct http_transaction *h, struct ctdlsession *c, char *which); StrBuf *ctdl_readtextmsg(struct ctdlsession *ctdl); StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source); void download_mime_component(struct http_transaction *h, struct ctdlsession *c, long msgnum, char *partnum); -- 2.30.2