From 6f4dbb5710da92c0976001e1b170384ace59cd06 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Mon, 4 Apr 2022 13:53:49 +0000 Subject: [PATCH] In reply to FossilOrigin-Name: 75dcc9ecb835e4b8e2c6c3ca2b2fdfa1de6c326a52c7e7de63d60d7745105d11 --- Makefile | 5 ++++ src/account.c | 8 +++--- src/account.h | 3 ++- src/l10n.h | 5 +++- src/notifications.c | 42 ++++++++++++++++++++++------- src/notifications.h | 14 +++++++--- src/status.c | 58 +++++++++++++++++++++++++++++++++++------ src/status.h | 5 ++-- src/timeline.c | 4 +-- static/in_reply_to.html | 3 +++ static/status.html | 1 + 11 files changed, 117 insertions(+), 31 deletions(-) create mode 100644 static/in_reply_to.html diff --git a/Makefile b/Makefile index 2ba72ca..205487a 100644 --- a/Makefile +++ b/Makefile @@ -79,12 +79,17 @@ $(PAGES_DIR)/config_general.chtml: $(PAGES_DIR)/config_general.html ./filec $< data_config_general_html > $@ $(PAGES_DIR)/config_appearance.chtml: $(PAGES_DIR)/config_appearance.html ./filec $< data_config_appearance_html > $@ +$(PAGES_DIR)/in_reply_to.chtml: $(PAGES_DIR)/in_reply_to.html + ./filec $< data_in_reply_to_html > $@ $(MASTODONT_DIR): git clone $(MASTODONT_URL) || true @echo -e "\033[38;5;13mRun 'make update' to update mastodont-c\033[0m" +install: + @echo "lol" + apache_start: ./scripts/fcgistarter.sh diff --git a/src/account.c b/src/account.c index 4fa7d31..c829235 100644 --- a/src/account.c +++ b/src/account.c @@ -28,7 +28,8 @@ #include "../static/index.chtml" #include "../static/account.chtml" -char* construct_account_page(struct mstdnt_account* acct, +char* construct_account_page(mastodont_t* api, + struct mstdnt_account* acct, struct mstdnt_status* statuses, size_t statuses_len, size_t* res_size) @@ -39,7 +40,7 @@ char* construct_account_page(struct mstdnt_account* acct, char* result; // Load statuses html - statuses_html = construct_statuses(statuses, statuses_len, NULL); + statuses_html = construct_statuses(api, statuses, statuses_len, NULL); if (!statuses_html) statuses_html = "Error in malloc!"; else @@ -83,7 +84,8 @@ void content_account(struct session* ssn, mastodont_t* api, char** data) account_page = construct_error("Couldn't load account info", NULL); } else { - account_page = construct_account_page(&acct, + account_page = construct_account_page(api, + &acct, statuses, status_len, NULL); diff --git a/src/account.h b/src/account.h index 67428d1..23ba46f 100644 --- a/src/account.h +++ b/src/account.h @@ -22,7 +22,8 @@ #include #include "session.h" -char* construct_account_page(struct mstdnt_account* acct, +char* construct_account_page(mastodont_t* api, + struct mstdnt_account* acct, struct mstdnt_status* statuses, size_t statuses_len, size_t* res_size); diff --git a/src/l10n.h b/src/l10n.h index 738f380..9e57a90 100644 --- a/src/l10n.h +++ b/src/l10n.h @@ -61,6 +61,7 @@ enum l10n_string L10N_LIKE, L10N_QUICK, L10N_VIEW, + L10N_IN_REPLY_TO, /* ERRORS */ L10N_PAGE_NOT_FOUND, @@ -138,6 +139,7 @@ static const char* const L10N[][_L10N_LEN] = { "Like", "Quick", "View", + "In reply to", /* ERRORS */ "Content not found", @@ -211,7 +213,8 @@ static const char* const L10N[][_L10N_LEN] = { "Impulso", "Me gusta", "RĂ¡pido", - "View (Translate me)", + "View", + "In reply to", /* ERRORS */ "Content not found", diff --git a/src/notifications.c b/src/notifications.c index 591c5e0..cd1d9b4 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -36,7 +36,15 @@ #include "../static/like_svg.chtml" #include "../static/repeat_svg.chtml" -char* construct_notification(struct mstdnt_notification* notif, int* size) +struct notification_args +{ + mastodont_t* api; + struct mstdnt_notification* notifs; +}; + +char* construct_notification(mastodont_t* api, + struct mstdnt_notification* notif, + int* size) { char* notif_html; int s = 0; @@ -44,7 +52,7 @@ char* construct_notification(struct mstdnt_notification* notif, int* size) if (notif->status) { // Construct status with notification_info - notif_html = construct_status(notif->status, &s, notif, 0); + notif_html = construct_status(api, notif->status, &s, notif, 0); } else { notif_html = construct_notification_action(notif, &s); @@ -73,7 +81,9 @@ char* construct_notification_action(struct mstdnt_notification* notif, int* size return notif_html; } -char* construct_notification_compact(struct mstdnt_notification* notif, int* size) +char* construct_notification_compact(mastodont_t* api, + struct mstdnt_notification* notif, + int* size) { char* notif_html; char* notif_stats = NULL; @@ -110,27 +120,39 @@ char* construct_notification_compact(struct mstdnt_notification* notif, int* siz static char* construct_notification_voidwrap(void* passed, size_t index, int* res) { - return construct_notification((struct mstdnt_notification*)passed + index, res); + struct notification_args* args = passed; + return construct_notification(args->api, args->notifs + index, res); } static char* construct_notification_compact_voidwrap(void* passed, size_t index, int* res) { - return construct_notification_compact((struct mstdnt_notification*)passed + index, res); + struct notification_args* args = passed; + return construct_notification_compact(args->api, args->notifs + index, res); } -char* construct_notifications(struct mstdnt_notification* notifs, +char* construct_notifications(mastodont_t* api, + struct mstdnt_notification* notifs, size_t size, size_t* ret_size) { - return construct_func_strings(construct_notification_voidwrap, notifs, size, ret_size); + struct notification_args args = { + .api = api, + .notifs = notifs + }; + return construct_func_strings(construct_notification_voidwrap, &args, size, ret_size); } -char* construct_notifications_compact(struct mstdnt_notification* notifs, +char* construct_notifications_compact(mastodont_t* api, + struct mstdnt_notification* notifs, size_t size, size_t* ret_size) { + struct notification_args args = { + .api = api, + .notifs = notifs + }; return construct_func_strings(construct_notification_compact_voidwrap, - notifs, + &args, size, ret_size); } @@ -159,7 +181,7 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data) if (mastodont_get_notifications(api, &args, &storage, ¬ifs, ¬ifs_len) == 0) { - notif_html = construct_notifications(notifs, notifs_len, NULL); + notif_html = construct_notifications(api, notifs, notifs_len, NULL); mstdnt_cleanup_notifications(notifs, notifs_len); } else diff --git a/src/notifications.h b/src/notifications.h index 38db6da..83b0f4c 100644 --- a/src/notifications.h +++ b/src/notifications.h @@ -22,13 +22,19 @@ #include "session.h" #include "type_string.h" -char* construct_notification(struct mstdnt_notification* notif, int* size); +char* construct_notification(mastodont_t* api, + struct mstdnt_notification* notif, + int* size); char* construct_notification_action(struct mstdnt_notification* notif, int* size); -char* construct_notification_compact(struct mstdnt_notification* notif, int* size); -char* construct_notifications(struct mstdnt_notification* notifs, +char* construct_notification_compact(mastodont_t* api, + struct mstdnt_notification* notif, + int* size); +char* construct_notifications(mastodont_t* api, + struct mstdnt_notification* notifs, size_t size, size_t* ret_size); -char* construct_notifications_compact(struct mstdnt_notification* notifs, +char* construct_notifications_compact(mastodont_t* api, + struct mstdnt_notification* notifs, size_t size, size_t* ret_size); diff --git a/src/status.c b/src/status.c index 442fc35..9674dc5 100644 --- a/src/status.c +++ b/src/status.c @@ -34,9 +34,16 @@ // Pages #include "../static/status.chtml" #include "../static/notification.chtml" +#include "../static/in_reply_to.chtml" #define NUM_STR "%u" +struct status_args +{ + mastodont_t* api; + struct mstdnt_status* status; +}; + int try_post_status(struct session* ssn, mastodont_t* api) { if (!(ssn->post.content)) return 1; @@ -109,7 +116,32 @@ int try_interact_status(struct session* ssn, mastodont_t* api, char* id) return 0; } -char* construct_status(struct mstdnt_status* status, +char* construct_in_reply_to(mastodont_t* api, struct mstdnt_status* status, size_t* size) +{ + char* irt_html; + size_t s; + struct mstdnt_storage storage; + struct mstdnt_account acct; + + mastodont_get_account(api, + config_experimental_lookup, + status->in_reply_to_account_id, + &acct, + &storage, + NULL); + + s = easprintf(&irt_html, data_in_reply_to_html, + config_url_prefix, + status->in_reply_to_id, + L10N[L10N_EN_US][L10N_IN_REPLY_TO], + status->in_reply_to_account_id); + + if (size) *size = s; + return irt_html; +} + +char* construct_status(mastodont_t* api, + struct mstdnt_status* status, int* size, struct mstdnt_notification* notif, uint8_t flags) @@ -123,6 +155,7 @@ char* construct_status(struct mstdnt_status* status, char* attachments = NULL; char* emoji_reactions = NULL; char* notif_info = NULL; + char* in_reply_to_str = NULL; if (status->replies_count) easprintf(&reply_count, NUM_STR, status->replies_count); if (status->reblogs_count) @@ -139,7 +172,9 @@ char* construct_status(struct mstdnt_status* status, notif->account->display_name, notification_type_str(notif->type), notification_type_svg(notif->type)); - + + if (status->in_reply_to_id && status->in_reply_to_account_id) + in_reply_to_str = construct_in_reply_to(api, status, NULL); size_t s = easprintf(&stat_html, data_status_html, status->id, @@ -164,6 +199,7 @@ char* construct_status(struct mstdnt_status* status, status->id, status->bookmarked ? "un" : "", status->bookmarked ? "Remove Bookmark" : "Bookmark", + in_reply_to_str ? in_reply_to_str : "", status->content, attachments ? attachments : "", emoji_reactions ? emoji_reactions : "", @@ -189,6 +225,7 @@ char* construct_status(struct mstdnt_status* status, if (reply_count) free(reply_count); if (repeat_count) free(repeat_count); if (favourites_count) free(favourites_count); + if (in_reply_to_str) free(in_reply_to_str); if (attachments) free(attachments); if (emoji_reactions) free(emoji_reactions); if (notif) free(notif_info); @@ -197,12 +234,17 @@ char* construct_status(struct mstdnt_status* status, static char* construct_status_voidwrap(void* passed, size_t index, int* res) { - return construct_status((struct mstdnt_status*)passed + index, res, NULL, 0); + struct status_args* args = passed; + return construct_status(args->api, args->status + index, res, NULL, 0); } -char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size) +char* construct_statuses(mastodont_t* api, struct mstdnt_status* statuses, size_t size, size_t* ret_size) { - return construct_func_strings(construct_status_voidwrap, statuses, size, ret_size); + struct status_args args = { + .api = api, + .status = statuses, + }; + return construct_func_strings(construct_status_voidwrap, &args, size, ret_size); } void status_interact(struct session* ssn, mastodont_t* api, char** data) @@ -245,10 +287,10 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, int is_r mastodont_get_status(api, data[0], &status_storage, &status); // Before... - before_html = construct_statuses(statuses_before, stat_before_len, NULL); + before_html = construct_statuses(api, statuses_before, stat_before_len, NULL); // Current status - stat_html = construct_status(&status, NULL, NULL, STATUS_FOCUSED); + stat_html = construct_status(api, &status, NULL, NULL, STATUS_FOCUSED); if (is_reply) { stat_reply = reply_status(data[0], @@ -256,7 +298,7 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, int is_r } // After... - after_html = construct_statuses(statuses_after, stat_after_len, NULL); + after_html = construct_statuses(api, statuses_after, stat_after_len, NULL); easprintf(&output, "%s%s%s%s", before_html ? before_html : "", diff --git a/src/status.h b/src/status.h index 490e15e..df15507 100644 --- a/src/status.h +++ b/src/status.h @@ -27,6 +27,7 @@ #define STATUS_FOCUSED (1<<0) #define STATUS_EMOJI_PICKER (1<<1) +char* construct_in_reply_to(mastodont_t* api, struct mstdnt_status* status, size_t* size); int try_post_status(struct session* ssn, mastodont_t* api); int try_interact_status(struct session* ssn, mastodont_t* api, char* id); void content_status_create(struct session* ssn, mastodont_t* api, char** data); @@ -35,8 +36,8 @@ void content_status_create(struct session* ssn, mastodont_t* api, char** data); char* construct_post_box(char* reply_id, char* default_content, int* size); -char* construct_status(struct mstdnt_status* status, int* size, struct mstdnt_notification* notif, uint8_t flags); -char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size); +char* construct_status(mastodont_t* api, struct mstdnt_status* status, int* size, struct mstdnt_notification* notif, uint8_t flags); +char* construct_statuses(mastodont_t* api, struct mstdnt_status* statuses, size_t size, size_t* ret_size); // Status frontends void status_view(struct session* ssn, mastodont_t* api, char** data); diff --git a/src/timeline.c b/src/timeline.c index 1ca0a79..1081628 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -60,7 +60,7 @@ void tl_public(struct session* ssn, mastodont_t* api, int local) } else { // Construct statuses into HTML - status_format = construct_statuses(statuses, status_count, &statuses_html_count); + status_format = construct_statuses(api, statuses, status_count, &statuses_html_count); if (!status_format) status_format = "Error in malloc!"; } @@ -124,7 +124,7 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id) } else { // Construct statuses into HTML - status_format = construct_statuses(statuses, status_count, &statuses_html_count); + status_format = construct_statuses(api, statuses, status_count, &statuses_html_count); if (!status_format) status_format = "Error in malloc!"; cleanup = 1; diff --git a/static/in_reply_to.html b/static/in_reply_to.html new file mode 100644 index 0000000..cd8e744 --- /dev/null +++ b/static/in_reply_to.html @@ -0,0 +1,3 @@ + + %s %s + diff --git a/static/status.html b/static/status.html index 07e9c52..c4e8266 100644 --- a/static/status.html +++ b/static/status.html @@ -37,6 +37,7 @@ + %s %s