[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
No known key found for this signature in database
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;
}
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);
}
public static function groupTagToName(string $nickname, string $uri): string
{
return '!' . $nickname . '@' . parse_url($uri, \PHP_URL_HOST);
}
public function onPluginVersion(array &$versions): bool
{
$versions[] = [

View File

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

View File

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