diff --git a/perl/timeline.pm b/perl/timeline.pm new file mode 100644 index 0000000..ad088cd --- /dev/null +++ b/perl/timeline.pm @@ -0,0 +1,24 @@ +package timeline; +use strict; +use warnings; +use Exporter 'import'; + +our @EXPORT = qw( generate_attachment ); + +use template_helpers 'to_template'; +use icons 'get_icon'; + +sub content_timeline +{ + my ($ssn, $data, $statuses, $title, $show_post_box) = @_; + + my %vars = ( + prefix => '', + ssn => $ssn, + statuses => $statuses, + title => $title, + post_box => $show_post_box, + ); + + to_template(\&vars, \&data->{'attachment.tt'}); +} diff --git a/src/global_perl.h b/src/global_perl.h index 78e501b..bbe8a8a 100644 --- a/src/global_perl.h +++ b/src/global_perl.h @@ -32,8 +32,10 @@ static PerlInterpreter* perl; extern HV* template_files; extern pthread_mutex_t perl_mutex; -#define perl_lock() if(1) { pthread_mutex_lock(&perl_mutex); } -#define perl_unlock() if(1) { pthread_mutex_unlock(&perl_mutex); } +#define perl_lock() do { pthread_mutex_lock(&perl_mutex); } while (1) +#define perl_unlock() do { pthread_mutex_unlock(&perl_mutex); } while (1) + +#define ARG_UNDEFINED() do { XPUSHs(&PL_sv_undef); } while (1) void init_template_files(); void cleanup_template_files(); diff --git a/src/status.c b/src/status.c index e93ead7..fb1998e 100644 --- a/src/status.c +++ b/src/status.c @@ -948,15 +948,15 @@ void content_status(PATH_ARGS, uint8_t flags) PUSHMARK(SP); HV* session_hv = perlify_session(ssn); XPUSHs(newRV_inc((SV*)session_hv)); - XPUSHs(newRV_inc((SV*)template_files)); - XPUSHs(newRV_inc((SV*)perlify_status(&status))); + XPUSHs(newRV_noinc((SV*)template_files)); + XPUSHs(newRV_noinc((SV*)perlify_status(&status))); if (statuses_before) - XPUSHs(newRV_inc((AV*)perlify_statuses(statuses_before, stat_before_len))); + XPUSHs(newRV_noinc((AV*)perlify_statuses(statuses_before, stat_before_len))); else XPUSHs(&PL_sv_undef); if (statuses_after) - XPUSHs(newRV_inc((AV*)perlify_statuses(statuses_after, stat_after_len))); + XPUSHs(newRV_noinc((AV*)perlify_statuses(statuses_after, stat_after_len))); else XPUSHs(&PL_sv_undef); // ARGS diff --git a/src/timeline.c b/src/timeline.c index 445523f..0962d86 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -30,6 +30,7 @@ #include "query.h" #include "error.h" #include "string_helpers.h" +#include "perl_global.h" #include "../static/timeline_options.ctmpl" #include "../static/navigation.ctmpl" @@ -44,65 +45,41 @@ void content_timeline(FCGX_Request* req, char* header_text, int show_post_box) { - size_t statuses_html_count = 0; - char* status_format = NULL, - * header = NULL, - * post_box = NULL, - * navigation_box = NULL, - * timeline_options, - * output = NULL, - * start_id; - - if (storage->error) - status_format = construct_error(storage->error, E_ERROR, 1, NULL); - else - { - // Construct statuses into HTML - status_format = construct_statuses(ssn, api, statuses, statuses_len, NULL, &statuses_html_count); - if (!status_format) - status_format = construct_error("No statuses", E_NOTICE, 1, NULL); - } - - // Create post box - if (show_post_box) - post_box = construct_post_box(NULL, "", NULL); - - if (statuses) - { - // If not set, set it - start_id = keystr(ssn->post.start_id) ? keystr(ssn->post.start_id) : statuses[0].id; - navigation_box = construct_navigation_box(start_id, - statuses[0].id, - statuses[statuses_len-1].id, - NULL); - } - - // Create timeline options/menubar - struct timeline_options_template todata = { - .only_media = "Only media?", - .replies = "Replies?", - .only_media_active = keyint(ssn->post.only_media) ? "checked" : NULL, - }; - - timeline_options = tmpl_gen_timeline_options(&todata, NULL); - - // Display a header bar, usually customized for specific pages - if (header_text) - { - easprintf(&header, "