AmendHub

Download:

jcs

/

subtext

/

amendments

/

195

board: Make menu options const, improve prompts


jcs made amendment 195 over 2 years ago
--- board.c Sat Jul 2 23:15:56 2022 +++ board.c Tue Jul 12 10:42:10 2022 @@ -125,7 +125,7 @@ void board_delete_post(struct session *s, struct board void board_show(struct session *s, short id) { - static struct session_menu_option opts[] = { + static const struct session_menu_option opts[] = { { '#', "#0123456789", "Read post [#]" }, { '<', "<", "Previous page of posts" }, { 'l', "Ll", "List posts" }, @@ -134,6 +134,7 @@ board_show(struct session *s, short id) { 'q', "QqXx", "Return to main menu" }, { '?', "?", "List menu options" }, }; + char prompt[7 + BOARD_NAME_LENGTH]; struct board *board = NULL; size_t n, nall_post_ids, page, pages, npost_ids; unsigned long *post_ids = NULL; @@ -160,6 +161,8 @@ board_show(struct session *s, short id) show_help = false; done = false; + snprintf(prompt, sizeof(prompt), "Boards:%s", board->name); + while (!done && !s->ending) { if (find_post_ids) { if (post_ids != NULL) { @@ -183,7 +186,7 @@ board_show(struct session *s, short id) show_list = false; } - c = session_menu(s, board->description, board->name, opts, + c = session_menu(s, board->description, prompt, opts, nitems(opts), show_help); show_help = false; @@ -514,9 +517,9 @@ short board_post_read(struct session *s, struct board *board, unsigned long id, short idx) { - static struct session_menu_option opts[] = { + static const struct session_menu_option opts[] = { { '#', "#0123456789", "Read post [#]" }, - { 'd', "Dd", "Delete this post (if permitted)" }, + { 'd', "Dd", "Delete this post" }, { 'r', "Rr", "Reply to this post" }, { 'q', "QqXx", "Return to threads" }, { '?', "?", "List these options" }, @@ -525,8 +528,9 @@ board_post_read(struct session *s, struct board *board struct board_thread thread; struct board_post post; struct username_cache *sender, *recipient; + struct session_menu_option *dopts = NULL; unsigned long new_id; - char prompt[BOARD_NAME_LENGTH + 8]; + char prompt[7 + BOARD_NAME_LENGTH + 8]; size_t n, size; short ret = POST_READ_RETURN_DONE; char c; @@ -551,6 +555,14 @@ board_post_read(struct session *s, struct board *board nboard_thread_object_fields, data, size, &thread, true); free(data); + dopts = xmalloc(sizeof(opts)); + memcpy(dopts, opts, sizeof(opts)); + if (!(s->user && (s->user->is_sysop || + s->user->id == post.sender_user_id))) { + /* disable deleting */ + dopts[1].key[0] = '\0'; + } + sender = user_find_username(post.sender_user_id); strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", @@ -568,10 +580,11 @@ board_post_read(struct session *s, struct board *board session_output(s, post.body, post.body_size); session_printf(s, "\r\n"); - snprintf(prompt, sizeof(prompt), "%s:%ld", board->name, post.id); + snprintf(prompt, sizeof(prompt), "Boards:%s:%ld", board->name, + post.id); while (!done && !s->ending) { - c = session_menu(s, thread.subject, prompt, opts, + c = session_menu(s, thread.subject, prompt, dopts, nitems(opts), show_help); show_help = false;