Finish statuses
FossilOrigin-Name: 4fe6d637a9f0610b978c32c1a39851546b141c37fd275ee5d44c57884a528a12
This commit is contained in:
parent
b745b140d9
commit
70b3fd7611
5 changed files with 23 additions and 10 deletions
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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\/?>| )>.*?)(?:<br\/?>|$)/<span class="greentext">$1<\/span><br>/gs;
|
||||
$text =~ s/((?:^|<br\/?>| )<.*?)(?:<br\/?>|$)/<span class="bluetext">$1<\/span><br>/gs;
|
||||
$text =~ s/((?:^|<br\/?>| )\^.*?)(?:<br\/?>|$)/<span class="yellowtext">$1<\/span><br>/gs;
|
||||
$text =~ s/(>.*?)(?=<|$)/<span class="greentext">$1<\/span>/gs;
|
||||
$text =~ s/(<.*?)(?=<|$)/<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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue