Finish statuses

FossilOrigin-Name: 4fe6d637a9f0610b978c32c1a39851546b141c37fd275ee5d44c57884a528a12
This commit is contained in:
nekobit 2022-08-03 05:08:37 +00:00
parent b745b140d9
commit 70b3fd7611
5 changed files with 23 additions and 10 deletions

View file

@ -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,
);

View file

@ -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 = '(?=<a .*?mention.*?)<a .*?href="https?:\/\/(.*?)\/(?:@|users\/|\/u)?(.*?)?".*?>';
sub reltime_to_str
{
@ -21,9 +23,9 @@ sub reltime_to_str
sub greentextify
{
my $text = shift;
$text =~ s/((?:^|<br\/?>| )&gt;.*?)(?:<br\/?>|$)/<span class="greentext">$1<\/span><br>/gs;
$text =~ s/((?:^|<br\/?>| )&lt;.*?)(?:<br\/?>|$)/<span class="bluetext">$1<\/span><br>/gs;
$text =~ s/((?:^|<br\/?>| )\^.*?)(?:<br\/?>|$)/<span class="yellowtext">$1<\/span><br>/gs;
$text =~ s/(&gt;.*?)(?=<|$)/<span class="greentext">$1<\/span>/gs;
$text =~ s/(&lt;.*?)(?=<|$)/<span class="bluetext">$1<\/span>/gs;
$text =~ s/(?:^|>| )(\^.*?)(?=<|$)/<span class="yellowtext">$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/<a target="_parent" class="mention" href="$at$2$at$1">/gs;
$text;
}
sub get_mentions_from_content
{
my ($ssn, $status) = @_;
my $result = '';
my $acct;
# todo
while ($status->{'content'} =~
/<a .*?href=\"https?:\/\/(.*?)\/(?:@|users\/|u\/)?(.*?)?\".*?>@(?:<span>)?.*?(?:<\/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;

View file

@ -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 "<a .*?href=\"https?:\\/\\/(.*?)\\/(?:@|users/|u/)?(.*?)?\".*?>@(?:<span>)?.*?(?:<\\/span>)?"
char* reply_status(struct session* ssn, char* id, struct mstdnt_status* status)
{

View file

@ -434,7 +434,7 @@ char* reformat_status(struct session* ssn,
return res;
}
#define REGEX_MENTION "(?=<a .*?mention.*?)<a .*?href=\"https?:\\/\\/(.*?)\\/(?:@|users\\/)?(.*?)?\".*?>"
#define REGEX_MENTION "(?=<a .*?mention.*?)<a .*?href=\"https?:\\/\\/(?<url>.*?)\\/(?:@|users\\/)?(?<>.*?)?\".*?>"
char* make_mentions_local(char* content)
{

View file

@ -59,7 +59,7 @@
[% IF status.spoiler_text %]
<span class="title">[% emojify(escape(status.spoiler_text), status.emojis) %]</span>
[% END %]
[% greentextify(emojify(status.content, status.emojis)) %]
[% greentextify(emojify(fix_mentions(status.content), status.emojis)) %]
</span>
[% IF status.media_attachments %]
<div class="attachments">