From 70b3fd761125fce921c35f3d21e623dc50f28ae9 Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 3 Aug 2022 05:08:37 +0000 Subject: [PATCH] Finish statuses FossilOrigin-Name: 4fe6d637a9f0610b978c32c1a39851546b141c37fd275ee5d44c57884a528a12 --- perl/status.pm | 3 ++- perl/string_helpers.pm | 24 ++++++++++++++++++------ src/reply.c | 2 +- src/status.c | 2 +- templates/status.tt | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/perl/status.pm b/perl/status.pm index d491058..b4249a3 100644 --- a/perl/status.pm +++ b/perl/status.pm @@ -2,7 +2,7 @@ package status; use strict; use warnings; use HTML::Escape 'escape_html'; -use string_helpers qw( reltime_to_str greentextify emojify format_username ); +use string_helpers qw( reltime_to_str greentextify emojify format_username localize_mentions ); use icons qw( get_icon visibility_to_icon ); use attachments 'generate_attachment'; use postbox 'generate_postbox'; @@ -31,6 +31,7 @@ sub generate_status greentextify => \&greentextify, emojify => \&emojify, escape => \&escape_html, + fix_mentions => \&localize_mentions, format_username => \&format_username, make_postbox => \&generate_postbox, ); diff --git a/perl/string_helpers.pm b/perl/string_helpers.pm index 622f51c..6dfeb65 100644 --- a/perl/string_helpers.pm +++ b/perl/string_helpers.pm @@ -4,7 +4,9 @@ use warnings; use HTML::Escape 'escape_html'; use Exporter 'import'; -our @EXPORT = qw( reltime_to_str greentextify emojify format_username get_mentions_from_content ); +our @EXPORT = qw( reltime_to_str greentextify emojify format_username get_mentions_from_content localize_mentions ); + +my $re_mentions = '(?='; sub reltime_to_str { @@ -21,9 +23,9 @@ sub reltime_to_str sub greentextify { my $text = shift; - $text =~ s/((?:^|| )>.*?)(?:|$)/$1<\/span>
/gs; - $text =~ s/((?:^|| )<.*?)(?:|$)/$1<\/span>
/gs; - $text =~ s/((?:^|| )\^.*?)(?:|$)/$1<\/span>
/gs; + $text =~ s/(>.*?)(?=<|$)/$1<\/span>/gs; + $text =~ s/(<.*?)(?=<|$)/$1<\/span>/gs; + $text =~ s/(?:^|>| )(\^.*?)(?=<|$)/$1<\/span>/gs; $text; } @@ -48,17 +50,27 @@ sub format_username emojify(escape_html($account->{display_name}), $account->{emojis}); } +sub localize_mentions +{ + my $text = shift; + # idk how to work around this + my $at = '@'; + + $text =~ s/$re_mentions/
/gs; + $text; +} + sub get_mentions_from_content { my ($ssn, $status) = @_; my $result = ''; my $acct; - # todo while ($status->{'content'} =~ /@(?:)?.*?(?:<\/span>)?/gs) { $acct = $2 . '@' . $1; - $result .= '@' . $acct . ' ' if $ssn->{account}->{acct} eq $acct; + # TODO this does not account for the domain (alt interference) + $result .= '@' . $acct unless $ssn->{account}->{acct} eq $2; } ($status->{account}->{acct} eq $ssn->{account}->{acct}) ? $result : '@' . $status->{account}->{acct} . ' ' . $result; diff --git a/src/reply.c b/src/reply.c index 2e9dc0b..7203cde 100644 --- a/src/reply.c +++ b/src/reply.c @@ -75,7 +75,7 @@ char* construct_post_box(struct mstdnt_status* reply_status, * so we just grep for regex href * - Misskey/Mastodon adds an @ symbol in the href param, while pleroma adds /users and honk adds /u */ -#define REGEX_REPLY "" +#define REGEX_REPLY "@(?:)?.*?(?:<\\/span>)?" char* reply_status(struct session* ssn, char* id, struct mstdnt_status* status) { diff --git a/src/status.c b/src/status.c index 83adbf9..e93ead7 100644 --- a/src/status.c +++ b/src/status.c @@ -434,7 +434,7 @@ char* reformat_status(struct session* ssn, return res; } -#define REGEX_MENTION "(?=" +#define REGEX_MENTION "(?=.*?)\\/(?:@|users\\/)?(?<>.*?)?\".*?>" char* make_mentions_local(char* content) { diff --git a/templates/status.tt b/templates/status.tt index f77940c..b87821a 100644 --- a/templates/status.tt +++ b/templates/status.tt @@ -59,7 +59,7 @@ [% IF status.spoiler_text %] [% emojify(escape(status.spoiler_text), status.emojis) %] [% END %] - [% greentextify(emojify(status.content, status.emojis)) %] + [% greentextify(emojify(fix_mentions(status.content), status.emojis)) %] [% IF status.media_attachments %]