[COMPONENT][FreeNetwork] Mention and Group tags in notes are handled differently

This commit is contained in:
Diogo Peralta Cordeiro 2022-02-21 04:52:30 +00:00
parent 7678e155d9
commit c380cbd846
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
3 changed files with 30 additions and 9 deletions

View File

@ -500,11 +500,16 @@ class FreeNetwork extends Component
return false; return false;
} }
public static function mentionToName(string $nickname, string $uri): string public static function mentionTagToName(string $nickname, string $uri): string
{ {
return '@' . $nickname . '@' . parse_url($uri, \PHP_URL_HOST); return '@' . $nickname . '@' . parse_url($uri, \PHP_URL_HOST);
} }
public static function groupTagToName(string $nickname, string $uri): string
{
return '!' . $nickname . '@' . parse_url($uri, \PHP_URL_HOST);
}
public function onPluginVersion(array &$versions): bool public function onPluginVersion(array &$versions): bool
{ {
$versions[] = [ $versions[] = [

View File

@ -390,11 +390,19 @@ class Note extends Model
// Mentions // Mentions
foreach ($object->getNotificationTargets() as $mention) { foreach ($object->getNotificationTargets() as $mention) {
$attr['tag'][] = [ if ($mention->isGroup()) {
'type' => 'Mention', $attr['tag'][] = [
'href' => ($href = $mention->getUri()), 'type' => 'Group',
'name' => FreeNetwork::mentionToName($mention->getNickname(), $href), 'href' => ($href = $mention->getUri()),
]; 'name' => FreeNetwork::groupTagToName($mention->getNickname(), $href),
];
} else {
$attr['tag'][] = [
'type' => 'Mention',
'href' => ($href = $mention->getUri()),
'name' => FreeNetwork::mentionTagToName($mention->getNickname(), $href),
];
}
$attr['to'][] = $href; $attr['to'][] = $href;
} }

View File

@ -199,10 +199,18 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface
public function mention(Actor $actor): string public function mention(Actor $actor): string
{ {
if ($actor->getIsLocal()) { if ($actor->isGroup()) {
return "@{$actor->getNickname()}"; if ($actor->getIsLocal()) {
return "!{$actor->getNickname()}";
} else {
return FreeNetwork::groupTagToName($actor->getNickname(), $actor->getUri(type: Router::ABSOLUTE_URL));
}
} else { } else {
return FreeNetwork::mentionToName($actor->getNickname(), $actor->getUri(type: Router::ABSOLUTE_URL)); if ($actor->getIsLocal()) {
return "@{$actor->getNickname()}";
} else {
return FreeNetwork::mentionTagToName($actor->getNickname(), $actor->getUri(type: Router::ABSOLUTE_URL));
}
} }
} }