From 3ac0145efcfb9c383156d22004cb1caeaa21a7c2 Mon Sep 17 00:00:00 2001 From: nekobit Date: Mon, 1 Aug 2022 04:56:10 +0000 Subject: [PATCH] Postbox FossilOrigin-Name: fa0971dfd73b18da2b62d02dcb1f3aa5ef301d17c21efab4ece79d5a6981a297 --- perl/attachments.pm | 4 ++- perl/postbox.pm | 23 +++++++++++++ perl/status.pm | 3 ++ perl/string_helpers.pm | 12 +++++-- src/account.c | 1 + src/global_perl.c | 2 ++ templates/postbox.tt | 78 ++++++++++++++++++++++++++++++++++++++++++ templates/status.tt | 5 ++- 8 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 perl/postbox.pm create mode 100644 templates/postbox.tt diff --git a/perl/attachments.pm b/perl/attachments.pm index 6712fce..456deec 100644 --- a/perl/attachments.pm +++ b/perl/attachments.pm @@ -6,6 +6,7 @@ use Exporter 'import'; our @EXPORT = qw( generate_attachment ); use template_helpers 'to_template'; +use icons 'get_icon'; sub generate_attachment { @@ -15,7 +16,8 @@ sub generate_attachment prefix => '', ssn => $ssn, attachment => $att, - sensitive => $sensitive + sensitive => $sensitive, + icon => \&get_icon, ); to_template(\%vars, \$data->{'attachment.tt'}); diff --git a/perl/postbox.pm b/perl/postbox.pm new file mode 100644 index 0000000..a7c1e19 --- /dev/null +++ b/perl/postbox.pm @@ -0,0 +1,23 @@ +package postbox; +use strict; +use warnings; +use template_helpers 'to_template'; +use string_helpers qw( get_mentions_from_content ); +use Exporter 'import'; + +our @EXPORT = qw( generate_postbox ); + +sub generate_postbox +{ + my ($ssn, $data, $status) = @_; + + my %vars = ( + prefix => '', + ssn => $ssn, + data => $data, + status => $status, + mentionify => \&get_mentions_from_content, + ); + + to_template(\%vars, \$data->{'postbox.tt'}); +} diff --git a/perl/status.pm b/perl/status.pm index 1d61534..d491058 100644 --- a/perl/status.pm +++ b/perl/status.pm @@ -5,6 +5,7 @@ use HTML::Escape 'escape_html'; use string_helpers qw( reltime_to_str greentextify emojify format_username ); use icons qw( get_icon visibility_to_icon ); use attachments 'generate_attachment'; +use postbox 'generate_postbox'; use emojis 'generate_emoji'; use Exporter 'import'; @@ -20,6 +21,7 @@ sub generate_status prefix => '', ssn => $ssn, status => $status, + data => $data, # Functions icon => \&get_icon, rel_to_str => \&reltime_to_str, @@ -30,6 +32,7 @@ sub generate_status emojify => \&emojify, escape => \&escape_html, format_username => \&format_username, + make_postbox => \&generate_postbox, ); to_template(\%vars, \$data->{'status.tt'}); diff --git a/perl/string_helpers.pm b/perl/string_helpers.pm index 1d9041c..7f3399d 100644 --- a/perl/string_helpers.pm +++ b/perl/string_helpers.pm @@ -4,7 +4,7 @@ use warnings; use HTML::Escape 'escape_html'; use Exporter 'import'; -our @EXPORT = qw( reltime_to_str greentextify emojify format_username ); +our @EXPORT = qw( reltime_to_str greentextify emojify format_username get_mentions_from_content ); sub reltime_to_str { @@ -44,7 +44,13 @@ sub emojify sub format_username { - my $username = shift; - emojify escape_html($username); + my $account = shift; + emojify(escape_html($account->{display_name}), $account->{emojis}); } +sub get_mentions_from_content +{ + my $status = shift; + # todo + ""; +} diff --git a/src/account.c b/src/account.c index 93135a6..06290d7 100644 --- a/src/account.c +++ b/src/account.c @@ -900,6 +900,7 @@ HV* perlify_account(const struct mstdnt_account* acct) hvstores_int(acct_hv, "suspended", acct->suspended); hvstores_int(acct_hv, "locked", acct->locked); hvstores_int(acct_hv, "discoverable", acct->discoverable); + hvstores_ref(acct_hv, "emojis", perlify_emojis(acct->emojis, acct->emojis_len)); return acct_hv; } diff --git a/src/global_perl.c b/src/global_perl.c index 02093ce..4e089bb 100644 --- a/src/global_perl.c +++ b/src/global_perl.c @@ -25,6 +25,7 @@ #include "../templates/emoji_picker.ctt" #include "../templates/attachment.ctt" #include "../templates/emoji.ctt" +#include "../templates/postbox.ctt" HV* template_files; pthread_mutex_t perl_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -40,6 +41,7 @@ void init_template_files() hv_stores(template_files, "emoji_picker.tt", newSVpv(data_emoji_picker_tt, data_emoji_picker_tt_size)); hv_stores(template_files, "attachment.tt", newSVpv(data_attachment_tt, data_attachment_tt_size)); hv_stores(template_files, "emoji.tt", newSVpv(data_emoji_tt, data_emoji_tt_size)); + hv_stores(template_files, "postbox.tt", newSVpv(data_postbox_tt, data_postbox_tt_size)); } void cleanup_template_files() diff --git a/templates/postbox.tt b/templates/postbox.tt new file mode 100644 index 0000000..83f274e --- /dev/null +++ b/templates/postbox.tt @@ -0,0 +1,78 @@ +
+ [% IF status %] + + [% END %] +
+ +
+
+ + +
+ + + + + + + + + + +
+
+
+ +
+
+ +
+
+ diff --git a/templates/status.tt b/templates/status.tt index 1868547..a1f060a 100644 --- a/templates/status.tt +++ b/templates/status.tt @@ -8,7 +8,7 @@
- [% format_username(status.account.display_name) %] + [% format_username(status.account) %] [% status.account.acct %] - - +[% make_postbox(ssn, data, status) %]