From 3b334562bf650320cb179bbce754ee53abf78e07 Mon Sep 17 00:00:00 2001 From: nekobit Date: Sat, 20 Aug 2022 02:43:17 +0000 Subject: [PATCH] Perlify status interactions FossilOrigin-Name: de6177ca45c0d238fedbc8824f85220736453e0df45f3e2160ea6f027e763fae --- perl/account.pm | 20 +++++++++++++++++++- src/global_perl.c | 2 ++ src/status.c | 25 +++++++++++++------------ templates/status_interactions.tt | 5 +++++ 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 templates/status_interactions.tt diff --git a/perl/account.pm b/perl/account.pm index a9de118..5c320e4 100644 --- a/perl/account.pm +++ b/perl/account.pm @@ -4,7 +4,7 @@ use warnings; use Exporter 'import'; -our @EXPORT = qw( account content_statuses generate_account_list generate_account_item ); +our @EXPORT = qw( account content_statuses generate_account_list generate_account_item status_interactions ); use template_helpers 'to_template'; use l10n 'lang'; @@ -81,6 +81,24 @@ sub generate_account_list to_template(\%vars, \$data->{'accounts.tt'}); } +sub status_interactions +{ + my ($ssn, $data, $accounts, $label) = @_; + + my %vars = ( + prefix => '', + ssn => $ssn, + data => $data, + accounts => $accounts, + label => $label, + # Functions + create_account => sub { generate_account_item($ssn, $data, shift); }, + ); + + + to_template(\%vars, \$data->{'status_interactions.tt'}); +} + sub content_accounts { my ($ssn, $data, $acct, $relationship, $accounts, $title) = @_; diff --git a/src/global_perl.c b/src/global_perl.c index e74e2a7..d649478 100644 --- a/src/global_perl.c +++ b/src/global_perl.c @@ -50,6 +50,7 @@ #include "../templates/about.ctt" #include "../templates/license.ctt" #include "../templates/login.ctt" +#include "../templates/status_interactions.ctt" PerlInterpreter* my_perl; HV* template_files; @@ -90,6 +91,7 @@ void init_template_files(pTHX) hv_stores(template_files, "about.tt", newSVpv(data_about_tt, data_about_tt_size)); hv_stores(template_files, "license.tt", newSVpv(data_license_tt, data_license_tt_size)); hv_stores(template_files, "login.tt", newSVpv(data_login_tt, data_login_tt_size)); + hv_stores(template_files, "status_interactions.tt", newSVpv(data_status_interactions_tt, data_status_interactions_tt_size)); } void cleanup_template_files() diff --git a/src/status.c b/src/status.c index 97ba905..a4890ec 100644 --- a/src/status.c +++ b/src/status.c @@ -898,28 +898,29 @@ void content_status_interactions(FCGX_Request* req, 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); + PERL_STACK_INIT; + HV* session_hv = perlify_session(ssn); + XPUSHs(newRV_noinc((SV*)session_hv)); + XPUSHs(newRV_noinc((SV*)template_files)); + if (accts) + XPUSHs(newRV_noinc((SV*)perlify_accounts(accts, accts_len))); + else ARG_UNDEFINED(); + XPUSHs(newSVpv(label, 0)); - struct interactions_page_template tmpl = { - .back_ref = GET_ENV("HTTP_REFERER", req), - .interaction_str = label, - .accts = accounts_html - }; + PERL_STACK_SCALAR_CALL("account::status_interactions"); - char* output = tmpl_gen_interactions_page(&tmpl, NULL); + char* dup = PERL_GET_STACK_EXIT; struct base_page page = { .category = BASE_CAT_NONE, - .content = output, + .content = dup, + .session = session_hv, .sidebar_left = NULL }; render_base_page(&page, req, ssn, api); // Cleanup - free(accounts_html); - free(output); + Safefree(dup); } void content_status(PATH_ARGS, uint8_t flags) diff --git a/templates/status_interactions.tt b/templates/status_interactions.tt new file mode 100644 index 0000000..663fb07 --- /dev/null +++ b/templates/status_interactions.tt @@ -0,0 +1,5 @@ +

$label

+ +[% FOREACH i IN accounts %] + [% create_account(i) %] +[% END %]