From 0d26b5b06ca49395d302da171f70d53d5e670059 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Tue, 23 Oct 2018 11:21:13 +1000 Subject: [PATCH] More work on www tree stuff --- src/www_msgs.c | 227 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 179 insertions(+), 48 deletions(-) diff --git a/src/www_msgs.c b/src/www_msgs.c index ab21e22..a2f769c 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -96,7 +96,6 @@ char *www_msgs_arealist(struct user_record *user) { char *www_msgs_messagelist(struct user_record *user, int conference, int area, int skip) { struct msg_headers *mhrs; - stralloc page = EMPTY_STRALLOC; char buffer[4096]; int i; struct tm msg_date; @@ -108,7 +107,17 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i char *to; char *from; char *subject; + char datebuf[32]; + + stralloc url; + struct www_tag *page; + struct www_tag *cur_tag; + struct www_tag *child_tag; + struct www_tag *child_child_tag; + struct www_tag *child_child_child_tag; + struct www_tag *child_child_child_child_tag; + if (conference < 0 || conference >= ptr_vector_len(&conf.mail_conferences)) return NULL; struct mail_conference *mc = get_conf(conference); @@ -116,32 +125,62 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i return NULL; struct mail_area *ma = get_area(conference, area); - stralloc_copys(&page, "

"); - stralloc_cats(&page, mc->name); - stralloc_cats(&page, " - "); - stralloc_cats(&page, ma->name); - stralloc_cats(&page, "

\n"); + page = www_tag_new(NULL, ""); + cur_tag = www_tag_new("div", NULL); + www_tag_add_attrib(cur_tag, "class", "content-header"); + www_tag_add_child(page, cur_tag); + + child_tag = www_tag_new("h2", NULL); + www_tag_add_child(cur_tag, child_tag); + + child_child_tag = www_tag_new(NULL, mc->name); + www_tag_add_child(child_tag, child_child_tag); + + child_child_tag = www_tag_new(NULL, " - "); + www_tag_add_child(child_tag, child_child_tag); + + child_child_tag = www_tag_new(NULL, ma->name); + www_tag_add_child(child_tag, child_child_tag); if (ma->type != TYPE_NETMAIL_AREA) { - stralloc_cats(&page, "
New Message
\n"); + cur_tag = www_tag_new("div", NULL); + www_tag_add_attrib(cur_tag, "class", "button"); + www_tag_add_child(page, cur_tag); + + child_tag = www_tag_new("a", NULL); + + url = EMPTY_STRALLOC; + stralloc_cats(&url, conf.www_url); + stralloc_cats(&url, "msgs/new/"); + stralloc_cat_long(&url, conference); + stralloc_append1(&url, '/'); + stralloc_cat_long(&url, area); + stralloc_0(&url); + + www_tag_add_attrib(child_tag, "href", url.s); + free(url.s); + + www_tag_add_child(cur_tag, child_tag); + + child_child_tag = www_tag_new(NULL, "New Message"); + www_tag_add_child(child_tag, child_child_tag); } mhrs = read_message_headers(conference, area, user, 0); if (mhrs == NULL) { - stralloc_cats(&page, "

No Messages

\n"); + cur_tag = www_tag_new("h3", NULL); + www_tag_add_child(page, cur_tag); + + child_tag = www_tag_new(NULL, "No Messages"); + www_tag_add_child(cur_tag, child_tag); } else { - - stralloc_cats(&page, "
\n"); + cur_tag = www_tag_new("div", NULL); + www_tag_add_attrib(cur_tag, "class", "div-table"); + www_tag_add_child(page, cur_tag); jb = open_jam_base(ma->path); if (!jb) { - free(page.s); + www_tag_destroy(page); free_message_headers(mhrs); return NULL; } @@ -163,53 +202,143 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i to = www_sanitize(mhrs->msgs[i]->to); from = www_sanitize(mhrs->msgs[i]->from); subject = www_sanitize(mhrs->msgs[i]->subject); - if (msgbase_is_flagged(user, conference, area, mhrs->msgs[i]->msg_h->MsgNum)) { - if (conf.date_style == 1) { - snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); - } else { - snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } else if (mhrs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg) { - if (conf.date_style == 1) { - snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); - } else { - snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } else { - if (conf.date_style == 1) { - snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); - } else { - snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - } + child_tag = www_tag_new("div", NULL); + + if (msgbase_is_flagged(user, conference, area, mhrs->msgs[i]->msg_h->MsgNum)) { + www_tag_add_attrib(child_tag, "class", "msg-summary-flag"); + } else if (mhrs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg) { + www_tag_add_attrib(child_tag, "class", "msg-summary"); + } else { + www_tag_add_attrib(child_tag, "class", "msg-summary-seen"); + } + www_tag_add_child(cur_tag, child_tag); + + + child_child_tag = www_tag_new("div", NULL); + www_tag_add_attrib(child_child_tag, "class", "msg-summary-id"); + www_tag_add_child(child_tag, child_child_tag); + + url = EMPTY_STRALLOC; + stralloc_cat_long(&url, mhrs->msgs[i]->msg_no + 1); + stralloc_0(&url); + + child_child_child_tag = www_tag_new(NULL, url.s); + free(url.s); + www_tag_add_child(child_child_tag, child_child_child_tag); + + child_child_tag = www_tag_new("div", NULL); + www_tag_add_attrib(child_child_tag, "class", "msg-summary-subject"); + www_tag_add_child(child_tag, child_child_tag); + + url = EMPTY_STRALLOC; + stralloc_cats(&url, conf.www_url); + stralloc_cats(&url, "msgs/"); + stralloc_cat_long(&url, conference); + stralloc_append1(&url, '/'); + stralloc_cat_long(&url, area); + stralloc_append1(&url, '/'); + stralloc_cat_long(&url, mhrs->msgs[i]->msg_h->MsgNum); + stralloc_0(&url); + + child_child_child_tag = www_tag_new("a", NULL); + www_tag_add_attrib(child_child_child_tag, "href", url.s); + free(url.s); + www_tag_add_child(child_child_tag, child_child_child_tag); + + child_child_child_child_tag = www_tag_new(NULL, subject); + www_tag_add_child(child_child_child_tag, child_child_child_child_tag); + + child_child_tag = www_tag_new("div", NULL); + www_tag_add_attrib(child_child_tag, "class", "msg-summary-from"); + www_tag_add_child(child_tag, child_child_tag); + + child_child_child_tag = www_tag_new(NULL, from); + www_tag_add_child(child_child_tag, child_child_child_tag); + + child_child_tag = www_tag_new("div", NULL); + www_tag_add_attrib(child_child_tag, "class", "msg-summary-to"); + www_tag_add_child(child_tag, child_child_tag); + + child_child_child_tag = www_tag_new(NULL, to); + www_tag_add_child(child_child_tag, child_child_child_tag); + + child_child_tag = www_tag_new("div", NULL); + www_tag_add_attrib(child_child_tag, "class", "msg-summary-date"); + www_tag_add_child(child_tag, child_child_tag); + + if (conf.date_style == 1) + strftime(datebuf, sizeof datebuf, "%H:%M %m-%d-%y", &msg_date); + else + strftime(datebuf, sizeof datebuf, "%H:%M %d-%m-%y", &msg_date); + + child_child_child_tag = www_tag_new(NULL, datebuf); + www_tag_add_child(child_child_tag, child_child_child_tag); + free(to); free(from); free(subject); - stralloc_cats(&page, buffer); } - stralloc_cats(&page, "
\n"); if (skip + 50 <= mhrs->msg_count) { - snprintf(buffer, sizeof buffer, - "
Next
\n", - conf.www_url, conference, area, skip + 50); - stralloc_cats(&page, buffer); + cur_tag = www_tag_new("div", NULL); + www_tag_add_attrib(cur_tag, "class", "msg-summary-next"); + www_tag_add_child(page, cur_tag); + + child_tag = www_tag_new("a", NULL); + + url = EMPTY_STRALLOC; + + stralloc_cats(&url, conf.www_url); + stralloc_cats(&url, "msgs/"); + stralloc_cat_long(&url, conference); + stralloc_append1(&url, '/'); + stralloc_cat_long(&url, area); + stralloc_cats(&url, "/?skip="); + stralloc_cat_long(&url, skip + 50); + stralloc_0(&url); + + www_tag_add_attrib(child_tag, "href", url.s); + free(url.s); + www_tag_add_child(cur_tag, child_tag); + child_child_tag = www_tag_new(NULL, "Next"); + www_tag_add_child(child_tag, child_child_tag); } if (skip > 0) { + cur_tag = www_tag_new("div", NULL); + www_tag_add_attrib(cur_tag, "class", "msg-summary-prev"); + www_tag_add_child(page, cur_tag); + child_tag = www_tag_new("a", NULL); + url = EMPTY_STRALLOC; if (skip - 50 < 0) { - snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area); + stralloc_cats(&url, conf.www_url); + stralloc_cats(&url, "msgs/"); + stralloc_cat_long(&url, conference); + stralloc_append1(&url, '/'); + stralloc_cat_long(&url, area); + stralloc_append1(&url, '/'); } else { - snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area, skip - 50); + stralloc_cats(&url, conf.www_url); + stralloc_cats(&url, "msgs/"); + stralloc_cat_long(&url, conference); + stralloc_append1(&url, '/'); + stralloc_cat_long(&url, area); + stralloc_cats(&url, "/?skip="); + stralloc_cat_long(&url, skip - 50); } - stralloc_cats(&page, buffer); + stralloc_0(&url); + www_tag_add_attrib(child_tag, "href", url.s); + free(url.s); + + www_tag_add_child(cur_tag, child_tag); + child_child_tag = www_tag_new(NULL, "Prev"); + www_tag_add_child(child_tag, child_child_tag); } free_message_headers(mhrs); } - stralloc_0(&page); - return page.s; + return www_tag_unwravel(page); } char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) { @@ -244,7 +373,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i char *nodename; struct fido_addr *nodeno; - struct www_tag *page = www_tag_new(NULL, ""); + struct www_tag *page; struct www_tag *cur_tag; struct www_tag *child_tag; struct www_tag *child_child_tag; @@ -344,6 +473,8 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i JAM_WriteLastRead(jb, user->id, &jlr); JAM_CloseMB(jb); free(jb); + + page = www_tag_new(NULL, ""); cur_tag = www_tag_new("div", NULL); www_tag_add_attrib(cur_tag, "class", "content-header");