AmendHub

Download:

jcs

/

subtext

/

amendments

/

365

board: Add FidoNet board list menu


jcs made amendment 365 about 1 year ago
--- board.c Sat Mar 4 22:32:17 2023 +++ board.c Tue Mar 7 21:11:12 2023 @@ -25,7 +25,7 @@ #include "logger.h" #include "user.h" -#define POSTS_PER_PAGE 20 +#define POSTS_PER_PAGE 20 #define POST_READ_RETURN_DONE -1 #define POST_READ_RETURN_LIST -2 @@ -105,6 +105,8 @@ const struct bile_object_field board_fidonet_post_obje member_size(struct board_fidonet_post, id), -1 }, { offsetof(struct board_fidonet_post, msgid), member_size(struct board_fidonet_post, msgid), -1 }, + { offsetof(struct board_fidonet_post, need_dispatch), + member_size(struct board_fidonet_post, need_dispatch), -1 }, { offsetof(struct board_fidonet_post, time), member_size(struct board_fidonet_post, time), -1 }, { offsetof(struct board_fidonet_post, from), @@ -151,15 +153,109 @@ unsigned long board_compose(struct session *s, struct void board_list_posts(struct session *s, struct board *board, size_t npost_Ids, unsigned long *post_ids, size_t page, size_t pages); short board_post_read(struct session *s, struct board *board, - unsigned long id, short idx); + char *prompt_prefix, unsigned long id, short idx); size_t board_find_post_ids(struct session *s, struct board *board, size_t *npost_ids, unsigned long **post_ids, size_t offset, size_t limit); void -board_show(struct session *s, short id) +board_list_fidonet_boards(struct session *s) { static const struct session_menu_option opts[] = { + { '#', "#", "Enter board to read" }, + { 'l', "Ll", "List FidoNet boards" }, + { 'q', "QqXx", "Return to main menu" }, + { '?', "?", "List menu options" }, + }; + char prompt[30]; + struct board *fboards = NULL, tboard; + size_t nfboards; + char c; + short ret, bn, n, i, j; + bool done, show_list, show_help; + + fboards = xcalloc(sizeof(struct board), db->nboards); + if (fboards == NULL) + return; + + nfboards = 0; + for (n = 0; n < db->nboards; n++) { + if (db->boards[n].fidonet_area[0]) { + memcpy(&fboards[nfboards], &db->boards[n], + sizeof(struct board)); + nfboards++; + } + } + + /* sort by area name */ + for (i = 0; i < nfboards; i++) { + for (j = 0; j < nfboards - i - 1; j++) { + if (strcmp(fboards[j].fidonet_area, + fboards[j + 1].fidonet_area) > 0) { + tboard = fboards[j]; + fboards[j] = fboards[j + 1]; + fboards[j + 1] = tboard; + } + } + } + + show_list = true; + show_help = false; + done = false; + + while (!done && !s->ending) { + if (show_list) { + session_printf(s, "{{B}}FidoNet Boards{{/B}}\r\n"); + session_printf(s, "%s# Name Description%s\r\n", + ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); + session_flush(s); + + for (n = 0; n < nfboards; n++) { + session_printf(s, "%2d %- 10.10s %s\r\n", + n + 1, + fboards[n].fidonet_area, + fboards[n].description); + } + session_flush(s); + + show_list = false; + } + + c = session_menu(s, "FidoNet Boards", "FidoNet", opts, + nitems(opts), show_help, "Board #", &bn); + show_help = false; + +handle_opt: + switch (c) { + case 'l': + show_list = true; + break; + case '#': +check_pn: + if (bn < 1 || bn > nfboards) { + session_printf(s, "Invalid board\r\n"); + session_flush(s); + break; + } + board_show(s, fboards[bn - 1].id, "FidoNet"); + break; + case '?': + show_help = true; + break; + default: + done = true; + break; + } + } + + if (fboards != NULL) + xfree(&fboards); +} + +void +board_show(struct session *s, short id, char *prompt_prefix) +{ + static const struct session_menu_option opts[] = { { '#', "#", "Enter post to read" }, { '<', "<", "Previous page of posts" }, { 'l', "Ll", "List posts" }, @@ -195,7 +291,10 @@ board_show(struct session *s, short id) show_help = false; done = false; - snprintf(prompt, sizeof(prompt), "Boards:%s", board->name); + if (prompt_prefix == NULL) + prompt_prefix = "Boards"; + + snprintf(prompt, sizeof(prompt), "%s:%s", prompt_prefix, board->name); while (!done && !s->ending) { if (find_post_ids) { @@ -264,7 +363,7 @@ check_pn: session_flush(s); break; } - ret = board_post_read(s, board, post_ids[pn - 1], pn); + ret = board_post_read(s, board, prompt, post_ids[pn - 1], pn); switch (ret) { case POST_READ_RETURN_DONE: break; @@ -608,8 +707,8 @@ post_compose_done: } short -board_post_read(struct session *s, struct board *board, unsigned long id, - short idx) +board_post_read(struct session *s, struct board *board, char *prompt_prefix, + unsigned long id, short idx) { static const struct session_menu_option opts[] = { { 'd', "Dd", "Delete this post" }, @@ -720,7 +819,7 @@ board_post_read(struct session *s, struct board *board session_printf(s, "\r\n"); } - snprintf(prompt, sizeof(prompt), "Boards:%s:%d", board->name, idx); + snprintf(prompt, sizeof(prompt), "%s:%d", prompt_prefix, idx); if (board->fidonet_area[0]) subject = fpost.subject; @@ -1304,7 +1403,8 @@ board_ingest_fidopkt(struct board *board, struct fidop } memset(&post, 0, sizeof(post)); - post.time = fidopkt->time; /* TODO: add/sub local offset */ + post.time = fidopkt->time - + ((db->config.timezone_utcoff * 60 * 60) / 100); post.body_size = fidopkt->message_len + 1; post.body = fidopkt->message; strlcpy(post.reply, fidopkt->reply, sizeof(post.reply)); --- board.h Fri Mar 3 15:56:50 2023 +++ board.h Tue Mar 7 20:44:42 2023 @@ -57,6 +57,7 @@ extern const size_t nboard_post_object_fields; struct board_fidonet_post { unsigned long id; struct fidopkt_msgid msgid; + short need_dispatch; time_t time; char from[32]; char subject[80]; @@ -82,7 +83,8 @@ struct board_thread { extern const struct bile_object_field board_thread_object_fields[]; extern const size_t nboard_thread_object_fields; -void board_show(struct session *s, short id); +void board_list_fidonet_boards(struct session *s); +void board_show(struct session *s, short id, char *prompt_prefix); short board_post_create(struct board *board, struct board_thread *thread, struct board_post *post); void board_delete_post(struct session *s, struct board *board, --- main_menu.c Thu Mar 2 09:38:45 2023 +++ main_menu.c Tue Mar 7 20:14:35 2023 @@ -136,7 +136,9 @@ main_menu_parse(char *opts, size_t len) } actionid = ACTION_NONE; - if (strcmp(action, "BOARD_SHOW_FIRST") == 0) + if (strcmp(action, "BOARD_LIST_FIDONET") == 0) + actionid = ACTION_BOARD_LIST_FIDONET; + else if (strcmp(action, "BOARD_SHOW_FIRST") == 0) actionid = ACTION_BOARD_SHOW_FIRST; else if (strcmp(action, "BOARD_SHOW_1") == 0) actionid = ACTION_BOARD_SHOW_1; --- main_menu.h Fri Nov 11 21:53:39 2022 +++ main_menu.h Tue Mar 7 20:14:51 2023 @@ -19,6 +19,7 @@ enum main_menu_action { ACTION_NONE = -1, + ACTION_BOARD_LIST_FIDONET, ACTION_BOARD_SHOW_FIRST, ACTION_BOARD_SHOW_1, ACTION_BOARD_SHOW_2, --- session.c Sat Mar 4 22:29:03 2023 +++ session.c Tue Mar 7 20:52:37 2023 @@ -260,7 +260,7 @@ get_another_char: switch (action) { case ACTION_BOARD_SHOW_FIRST: - board_show(s, 1); + board_show(s, 1, NULL); break; case ACTION_CHAT: chat_start(s, NULL); @@ -281,7 +281,7 @@ get_another_char: mail_menu(s); break; case ACTION_MAIL_COMPOSE: - mail_compose(s, NULL, NULL, NULL); + mail_compose(s, NULL, NULL, NULL, NULL); break; case ACTION_MOTD: session_print_motd(s, true); @@ -311,35 +311,38 @@ get_another_char: case ACTION_WHOS_ONLINE: session_who(s); break; + case ACTION_BOARD_LIST_FIDONET: + board_list_fidonet_boards(s); + break; case ACTION_BOARD_SHOW_1: - board_show(s, 1); + board_show(s, 1, NULL); break; case ACTION_BOARD_SHOW_2: - board_show(s, 2); + board_show(s, 2, NULL); break; case ACTION_BOARD_SHOW_3: - board_show(s, 3); + board_show(s, 3, NULL); break; case ACTION_BOARD_SHOW_4: - board_show(s, 4); + board_show(s, 4, NULL); break; case ACTION_BOARD_SHOW_5: - board_show(s, 5); + board_show(s, 5, NULL); break; case ACTION_BOARD_SHOW_6: - board_show(s, 6); + board_show(s, 6, NULL); break; case ACTION_BOARD_SHOW_7: - board_show(s, 7); + board_show(s, 7, NULL); break; case ACTION_BOARD_SHOW_8: - board_show(s, 8); + board_show(s, 8, NULL); break; case ACTION_BOARD_SHOW_9: - board_show(s, 9); + board_show(s, 9, NULL); break; case ACTION_BOARD_SHOW_10: - board_show(s, 10); + board_show(s, 10, NULL); break; case ACTION_SYSOP_MENU: if (!s->user || !s->user->is_sysop) { @@ -1623,7 +1626,7 @@ get_menu_option: goto get_menu_option; session_printf(s, "%c\r\n", c); - session_printf(s, "%s", invalid_option_help); + session_printf(s, invalid_option_help); session_flush(s); last_invalid = true; }