From ef3f71288393964e914f60e6f5701a379b3c3111 Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 8 Jun 2022 04:27:39 +0000 Subject: [PATCH] Like/boost pages FossilOrigin-Name: ac61288ee02687bbf2a6bef576c5599a47009df3253b9e3914292365a6e2a0f4 --- src/main.c | 3 + src/status.c | 108 +++++++++++++++++++++++--- src/status.h | 18 ++++- static/interactions_page.tmpl | 4 + static/status_interactions_label.tmpl | 4 +- 5 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 static/interactions_page.tmpl diff --git a/src/main.c b/src/main.c index 98dd5e8..bc5e8d0 100644 --- a/src/main.c +++ b/src/main.c @@ -77,6 +77,9 @@ int main(void) { "/status/create", content_status_create }, { "/status/:/interact", status_interact }, { "/status/:/reply", status_reply }, + { "/status/:/favourited_by", status_view_favourites }, + { "/status/:/boosted_by", status_view_reblogs }, + { "/status/:/reblogged_by", status_view_reblogs }, { "/status/:", status_view }, { "/notice/:", notice_redirect }, { "/about/license", content_about_license }, diff --git a/src/status.c b/src/status.c index 88f576f..4a7066a 100644 --- a/src/status.c +++ b/src/status.c @@ -35,6 +35,7 @@ #include "type_string.h" #include "string.h" #include "emoji.h" +#include "account.h" // Pages #include "../static/status.ctmpl" @@ -43,6 +44,7 @@ #include "../static/status_interactions_label.ctmpl" #include "../static/status_interactions.ctmpl" #include "../static/status_interaction_profile.ctmpl" +#include "../static/interactions_page.ctmpl" #include "../static/likeboost.ctmpl" #include "../static/reactions_btn.ctmpl" #include "../static/interaction_buttons.ctmpl" @@ -169,9 +171,16 @@ int try_interact_status(struct session* ssn, mastodont_t* api, char* id) return res; } -char* construct_status_interactions_label(char* header, int val, size_t* size) +char* construct_status_interactions_label(char* status_id, + int is_favourites, + char* header, + int val, + size_t* size) { struct status_interactions_label_template tdata = { + .prefix = config_url_prefix, + .status_id = status_id, + .action = is_favourites ? "favourited_by" : "reblogged_by", .header = header, .value = val, }; @@ -258,7 +267,8 @@ char* construct_interaction_buttons(struct session* ssn, return interaction_html; } -char* construct_status_interactions(int fav_count, +char* construct_status_interactions(char* status_id, + int fav_count, int reblog_count, struct mstdnt_account* fav_accounts, size_t fav_accounts_len, @@ -268,9 +278,9 @@ char* construct_status_interactions(int fav_count, { char* html; char* reblogs_label = reblog_count ? - construct_status_interactions_label("Reblogs", reblog_count, NULL) : NULL; + construct_status_interactions_label(status_id, 0, "Reblogs", reblog_count, NULL) : NULL; char* favourites_label = fav_count ? - construct_status_interactions_label("Favorites", fav_count, NULL) : NULL; + construct_status_interactions_label(status_id, 1, "Favorites", fav_count, NULL) : NULL; char* profiles = construct_status_interaction_profiles(reblog_accounts, fav_accounts, reblog_accounts_len, @@ -587,7 +597,8 @@ char* construct_status(struct session* ssn, &reblogs_storage, &reblogs, &reblogs_len); - interactions_html = construct_status_interactions(status->favourites_count, + interactions_html = construct_status_interactions(status->id, + status->favourites_count, status->reblogs_count, favourites, favourites_len, @@ -775,6 +786,82 @@ void status_reply(struct session* ssn, mastodont_t* api, char** data) content_status(ssn, api, data, STATUS_FOCUSED | STATUS_REPLY); } +void status_view_reblogs(struct session* ssn, mastodont_t* api, char** data) +{ + struct mstdnt_account* favourites = NULL; + struct mstdnt_storage storage = { 0 }; + size_t favourites_len = 0; + char* status_id = data[0]; + + mastodont_status_reblogged_by(api, + status_id, + &storage, + &favourites, + &favourites_len); + + content_status_interactions( + ssn, + api, + "Reblogs", + favourites, + favourites_len); + + mastodont_storage_cleanup(&storage); +} + +void status_view_favourites(struct session* ssn, mastodont_t* api, char** data) +{ + struct mstdnt_account* favourites = NULL; + struct mstdnt_storage storage = { 0 }; + size_t favourites_len = 0; + char* status_id = data[0]; + + mastodont_status_favourited_by(api, + status_id, + &storage, + &favourites, + &favourites_len); + + content_status_interactions( + ssn, + api, + "Favorites", + favourites, + favourites_len); + + mastodont_storage_cleanup(&storage); +} + +void content_status_interactions(struct session* ssn, + mastodont_t* api, + char* label, + struct mstdnt_account* accts, + size_t accts_len) +{ + char* accounts_html = construct_accounts(api, accts, accts_len, 0, NULL); + if (!accounts_html) + accounts_html = construct_error("No accounts", E_NOTICE, 1, NULL); + + struct interactions_page_template tmpl = { + .back_ref = getenv("HTTP_REFERER"), + .interaction_str = label, + .accts = accounts_html + }; + + char* output = tmpl_gen_interactions_page(&tmpl, NULL); + + struct base_page page = { + .category = BASE_CAT_NONE, + .content = output, + .sidebar_left = NULL + }; + render_base_page(&page, ssn, api); + + // Cleanup + free(accounts_html); + free(output); +} + void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t flags) { char* output; @@ -827,11 +914,12 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t render_base_page(&b, ssn, api); // Cleanup - if (before_html) free(before_html); - if (stat_html) free(stat_html); - if (after_html) free(after_html); - if (output) free(output); - if ((flags & STATUS_REPLY) == STATUS_REPLY) free(stat_reply); + free(before_html); + free(stat_html); + free(after_html); + free(output); + if ((flags & STATUS_REPLY) == STATUS_REPLY) + free(stat_reply); mstdnt_cleanup_statuses(statuses_before, stat_before_len); mstdnt_cleanup_statuses(statuses_after, stat_after_len); mstdnt_cleanup_status(&status); diff --git a/src/status.h b/src/status.h index adc2485..f6cad65 100644 --- a/src/status.h +++ b/src/status.h @@ -72,7 +72,8 @@ char* construct_in_reply_to(struct mstdnt_status* status, struct mstdnt_account* account, size_t* size); -char* construct_status_interactions(int fav_count, +char* construct_status_interactions(char* status_id, + int fav_count, int reblog_count, struct mstdnt_account* fav_accounts, size_t fav_accounts_len, @@ -86,7 +87,11 @@ char* construct_status_interaction_profiles(struct mstdnt_account* reblogs, size_t favourites_len, size_t* ret_size); char* construct_status_interaction_profile(struct interact_profile_args* args, size_t index, size_t* size); -char* construct_status_interactions_label(char* header, int val, size_t* size); +char* construct_status_interactions_label(char* status_id, + int is_favourites, + char* header, + int val, + size_t* size); char* reformat_status(struct session* ssn, char* content, struct mstdnt_emoji* emos, @@ -94,6 +99,15 @@ char* reformat_status(struct session* ssn, char* greentextify(char* content); char* make_mentions_local(char* content); +void status_view_reblogs(struct session* ssn, mastodont_t* api, char** data); +void status_view_favourites(struct session* ssn, mastodont_t* api, char** data); + +void content_status_interactions(struct session* ssn, + mastodont_t* api, + char* label, + struct mstdnt_account* accts, + size_t accts_len); + // Status frontends void status_view(struct session* ssn, mastodont_t* api, char** data); void status_reply(struct session* ssn, mastodont_t* api, char** data); diff --git a/static/interactions_page.tmpl b/static/interactions_page.tmpl new file mode 100644 index 0000000..46aea1b --- /dev/null +++ b/static/interactions_page.tmpl @@ -0,0 +1,4 @@ +
+

< {{ %s : interaction_str }}

+
+{{ %s : accts }} diff --git a/static/status_interactions_label.tmpl b/static/status_interactions_label.tmpl index f2d9273..6445520 100644 --- a/static/status_interactions_label.tmpl +++ b/static/status_interactions_label.tmpl @@ -1,4 +1,4 @@ -
+ {{%s:header}} {{%d:value}} -
+