AmendHub

Download:

jcs

/

subtext

/

amendments

/

253

board: Store each user's 'via' in each post

I saw this on another BBS and thought it was kind of neat to see
how each person connected when they made a post.

jcs made amendment 253 over 2 years ago
--- board.c Fri Jan 1 02:03:04 1904 +++ board.c Fri Sep 16 17:15:11 2022 @@ -87,6 +87,8 @@ struct bile_object_field board_post_object_fields[] = -1, offsetof(struct board_post, body_size) }, { offsetof(struct board_post, parent_post_id), member_size(struct board_post, parent_post_id), -1 }, + { offsetof(struct board_post, via), + member_size(struct board_post, via), -1 }, }; size_t nboard_post_object_fields = nitems(board_post_object_fields); @@ -397,10 +399,12 @@ board_compose(struct session *s, struct board *board, "board_compose thread"); post.sender_user_id = s->user->id; + strlcpy(post.via, s->via, sizeof(post.via)); session_printf(s, "{{B}}Compose %s{{/B}}\r\n", parent_post ? "Reply" : "New Post"); - session_printf(s, "{{B}}From:{{/B}} %s\r\n", s->user->username); + session_printf(s, "{{B}}From:{{/B}} %s (via %s)\r\n", + s->user->username, s->via); session_printf(s, "{{B}}To:{{/B}} %s\r\n", board->name); post_compose_start: @@ -587,8 +591,11 @@ board_post_read(struct session *s, struct board *board strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", localtime(&post.time)); - session_printf(s, "{{B}}From:{{/B}} %s\r\n", + session_printf(s, "{{B}}From:{{/B}} %s", sender ? sender->username : "(unknown)"); + if (post.via[0]) + session_printf(s, " (via %s)", post.via); + session_printf(s, "\r\n"); session_printf(s, "{{B}}To:{{/B}} %s\r\n", board->name); session_printf(s, "{{B}}Date:{{/B}} %s %s\r\n", time, db->config.timezone); --- board.h Thu Jun 30 13:36:04 2022 +++ board.h Fri Sep 16 13:44:29 2022 @@ -49,6 +49,7 @@ struct board_post { size_t body_size; char *body; unsigned long parent_post_id; + char via[10]; }; extern struct bile_object_field board_post_object_fields[]; extern size_t nboard_post_object_fields; --- db.c Tue Sep 13 23:49:37 2022 +++ db.c Fri Sep 16 16:54:03 2022 @@ -408,6 +408,56 @@ db_migrate(struct db *tdb, short is_new) xfree(&ids); break; } + case 9: { + /* 9->10, added board post via */ + size_t nposts, n, j, size; + unsigned long *ids = NULL; + struct board *board; + char *data; + struct board_post post; + short ret; + + db_cache_boards(tdb); + + for (n = 0; n < tdb->nboards; n++) { + board = &tdb->boards[n]; + nposts = bile_sorted_ids_by_type(board->bile, + BOARD_POST_RTYPE, &ids); + for (j = 0; j < nposts; j++) { + size = bile_read_alloc(board->bile, BOARD_POST_RTYPE, + ids[j], &data); + if (size == 0) + panic("failed fetching message %ld: %d", ids[j], + bile_error(board->bile)); + + /* pretend we read this much, just fill via with junk */ + size += member_size(struct board_post, via); + + bile_unmarshall_object(board->bile, + board_post_object_fields, nboard_post_object_fields, + data, size, &post, sizeof(post), true, "board_post"); + xfree(&data); + + /* zero out junk */ + memset(&post.via, 0, sizeof(post.via)); + + ret = bile_marshall_object(board->bile, + board_post_object_fields, nboard_post_object_fields, + &post, &data, &size, "board_post post"); + if (ret != 0 || size == 0) + panic("failed to marshall new post object"); + if (bile_write(board->bile, BOARD_POST_RTYPE, + post.id, data, size) != size) + panic("bile_write of post failed! %d", + bile_error(board->bile)); + + xfree(&data); + } + if (ids != NULL) + xfree(&ids); + } + break; + } } ver++; --- db.h Tue Sep 13 20:59:29 2022 +++ db.h Fri Sep 16 13:44:51 2022 @@ -23,7 +23,7 @@ #define DB_TYPE 'STDB' -#define DB_CUR_VERS 9 +#define DB_CUR_VERS 10 #define DB_TRUE 0x100 #define DB_FALSE 0x000