From 80afc0fa6c403f0fa0aa5a52b51dfc7cbf194292 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Mon, 27 Dec 2021 04:13:09 +0000 Subject: [PATCH] [TEMPLATES][Cards][Profile] Provide both actor uri and url, as well as full mention guidance --- components/FreeNetwork/FreeNetwork.php | 5 +++ plugins/ActivityPub/Util/Model/Note.php | 4 +-- .../assets/default_theme/css/pages/feeds.css | 3 -- src/Entity/Actor.php | 34 +++++++++---------- src/Twig/Extension.php | 21 ++++++------ src/Twig/Runtime.php | 11 ++++++ templates/actor/view.html.twig | 2 -- templates/cards/note/view.html.twig | 8 ++++- templates/cards/profile/view.html.twig | 31 +++++++++-------- 9 files changed, 69 insertions(+), 50 deletions(-) diff --git a/components/FreeNetwork/FreeNetwork.php b/components/FreeNetwork/FreeNetwork.php index 0efa3bbe67..9ad5021539 100644 --- a/components/FreeNetwork/FreeNetwork.php +++ b/components/FreeNetwork/FreeNetwork.php @@ -500,6 +500,11 @@ class FreeNetwork extends Component return false; } + public static function mentionToName(string $nickname, string $uri): string + { + return '@' . $nickname . '@' . parse_url($uri, \PHP_URL_HOST); + } + public function onPluginVersion(array &$versions): bool { $versions[] = [ diff --git a/plugins/ActivityPub/Util/Model/Note.php b/plugins/ActivityPub/Util/Model/Note.php index f620dd414b..ff1664a834 100644 --- a/plugins/ActivityPub/Util/Model/Note.php +++ b/plugins/ActivityPub/Util/Model/Note.php @@ -55,13 +55,13 @@ use App\Util\TemporaryFile; use Component\Attachment\Entity\ActorToAttachment; use Component\Attachment\Entity\AttachmentToNote; use Component\Conversation\Conversation; +use Component\FreeNetwork\FreeNetwork; use Component\Language\Entity\Language; use Component\Tag\Tag; use DateTime; use DateTimeInterface; use Exception; use InvalidArgumentException; -use const PHP_URL_HOST; use Plugin\ActivityPub\ActivityPub; use Plugin\ActivityPub\Entity\ActivitypubObject; use Plugin\ActivityPub\Util\Model; @@ -356,7 +356,7 @@ class Note extends Model $attr['tag'][] = [ 'type' => 'Mention', 'href' => ($href = $mention->getUri()), - 'name' => '@' . $mention->getNickname() . '@' . parse_url($href, PHP_URL_HOST), + 'name' => FreeNetwork::mentionToName($mention->getNickname(), $href), ]; $attr['to'][] = $href; } diff --git a/public/assets/default_theme/css/pages/feeds.css b/public/assets/default_theme/css/pages/feeds.css index 18d83cb1d9..aca13e0487 100644 --- a/public/assets/default_theme/css/pages/feeds.css +++ b/public/assets/default_theme/css/pages/feeds.css @@ -139,9 +139,6 @@ embed header { float: left; margin-left: 4px; } -.note-author-url::before { - content: '@'; -} .note-author-fullname { font-weight: bold; } diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 3f4b7c1d5d..180bccd195 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -465,26 +465,26 @@ class Actor extends Entity */ public function getUrl(int $type = Router::ABSOLUTE_URL): string { - $url = null; - if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) { - if ($this->getIsLocal()) { + if ($this->getIsLocal()) { + $url = null; + if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) { switch ($this->type) { - case self::PERSON: - case self::ORGANIZATION: - case self::BUSINESS: - case self::BOT: - $url = Router::url('actor_view_nickname', ['nickname' => $this->getNickname()], $type); - break; - case self::GROUP: - $url = Router::url('group_actor_view_nickname', ['nickname' => $this->getNickname()], $type); - break; - default: - throw new BugFoundException('Actor type added but `Actor::getUrl` was not updated'); + case self::PERSON: + case self::ORGANIZATION: + case self::BUSINESS: + case self::BOT: + $url = Router::url('actor_view_nickname', ['nickname' => $this->getNickname()], $type); + break; + case self::GROUP: + $url = Router::url('group_actor_view_nickname', ['nickname' => $this->getNickname()], $type); + break; + default: + throw new BugFoundException('Actor type added but `Actor::getUrl` was not updated'); } - } else { - return $this->getUri($type); + Event::handle('EndGetActorUrl', [$this, $type, &$url]); } - Event::handle('EndGetActorUrl', [$this, $type, &$url]); + } else { + return Router::url('actor_view_id', ['id' => $this->getId()], $type); } return $url; } diff --git a/src/Twig/Extension.php b/src/Twig/Extension.php index e7fd2cc904..9f5a25f93f 100644 --- a/src/Twig/Extension.php +++ b/src/Twig/Extension.php @@ -62,20 +62,21 @@ class Extension extends AbstractExtension return [ /** Twig function to output the 'active' class if the current route matches the given route */ new TwigFunction('active', [Runtime::class, 'isCurrentRouteActive']), - new TwigFunction('is_route', [Runtime::class, 'isCurrentRoute']), - new TwigFunction('get_note_actions', [Runtime::class, 'getNoteActions']), - new TwigFunction('get_extra_note_actions', [Runtime::class, 'getExtraNoteActions']), - new TwigFunction('show_stylesheets', [Runtime::class, 'getShowStylesheets']), - new TwigFunction('handle_event', [Runtime::class, 'handleEvent']), new TwigFunction('config', [Runtime::class, 'getConfig']), + new TwigFunction('dd', 'dd'), + new TwigFunction('die', 'die'), + new TwigFunction('get_extra_note_actions', [Runtime::class, 'getExtraNoteActions']), + new TwigFunction('get_feeds', [Runtime::class, 'getFeeds']), + new TwigFunction('get_note_actions', [Runtime::class, 'getNoteActions']), + new TwigFunction('handle_event', [Runtime::class, 'handleEvent']), + new TwigFunction('handle_override_stylesheet', [Runtime::class, 'handleOverrideStylesheet']), + new TwigFunction('handle_override_template_import', [Runtime::class, 'handleOverrideTemplateImport']), new TwigFunction('icon', [Runtime::class, 'embedSvgIcon'], ['needs_environment' => true]), new TwigFunction('is_firefox', [Runtime::class, 'isFirefox']), - new TwigFunction('handle_override_template_import', [Runtime::class, 'handleOverrideTemplateImport']), - new TwigFunction('handle_override_stylesheet', [Runtime::class, 'handleOverrideStylesheet']), + new TwigFunction('is_route', [Runtime::class, 'isCurrentRoute']), + new TwigFunction('mention', [Runtime::class, 'mention']), new TwigFunction('open_details', [Runtime::class, 'openDetails']), - new TwigFunction('get_feeds', [Runtime::class, 'getFeeds']), - new TwigFunction('die', 'die'), - new TwigFunction('dd', 'dd'), + new TwigFunction('show_stylesheets', [Runtime::class, 'getShowStylesheets']), ]; } } diff --git a/src/Twig/Runtime.php b/src/Twig/Runtime.php index 9b07bf0d79..6ee8ab8039 100644 --- a/src/Twig/Runtime.php +++ b/src/Twig/Runtime.php @@ -33,11 +33,13 @@ declare(strict_types = 1); namespace App\Twig; use App\Core\Event; +use App\Core\Router\Router; use App\Entity\Actor; use App\Entity\Feed; use App\Entity\Note; use App\Util\Common; use App\Util\Formatting; +use Component\FreeNetwork\FreeNetwork; use Functional as F; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; @@ -162,6 +164,15 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface return Feed::getFeeds($actor); } + public function mention(Actor $actor): string + { + if ($actor->getIsLocal()) { + return "@{$actor->getNickname()}"; + } else { + return FreeNetwork::mentionToName($actor->getNickname(), $actor->getUri(type: Router::ABSOLUTE_URL)); + } + } + // ---------------------------------------------------------- /** diff --git a/templates/actor/view.html.twig b/templates/actor/view.html.twig index 8dd0570a20..9ed7fcb034 100644 --- a/templates/actor/view.html.twig +++ b/templates/actor/view.html.twig @@ -1,7 +1,5 @@ {% extends 'feed/feed.html.twig' %} -{% set nickname = nickname|escape %} - {% block title %}{% trans %}%nickname%'s profile{% endtrans %}{% endblock %} {% block body %} diff --git a/templates/cards/note/view.html.twig b/templates/cards/note/view.html.twig index 73c5341270..df6a68d822 100644 --- a/templates/cards/note/view.html.twig +++ b/templates/cards/note/view.html.twig @@ -76,6 +76,7 @@ {% block note_author %} {# Microformat's h-card properties indicates a face icon is a "u-logo" #} +
{% if fullname is not null %} {{ fullname }} @@ -83,9 +84,10 @@ {{ nickname }} {% endif %}
+
- {{ nickname }} + {{ mention }} {% endblock note_author %} @@ -114,7 +116,9 @@ {% set actor = note.getActor() %} {% set nickname = actor.getNickname() %} {% set fullname = actor.getFullname() %} + {% set actor_uri = actor.getUri() %} {% set actor_url = actor.getUrl() %} + {% set mention = mention(actor) %} {% set note_language = note.getNoteLanguageShortDisplay() %}
@@ -147,7 +151,9 @@ {% set actor = note.getActor() %} {% set nickname = actor.getNickname() %} {% set fullname = actor.getFullname() %} + {% set actor_uri = actor.getUri() %} {% set actor_url = actor.getUrl() %} + {% set mention = mention(actor) %}
{{ block('note_sidebar') }} diff --git a/templates/cards/profile/view.html.twig b/templates/cards/profile/view.html.twig index b4304bee3b..63d509af42 100644 --- a/templates/cards/profile/view.html.twig +++ b/templates/cards/profile/view.html.twig @@ -4,6 +4,9 @@ {% set actor_tags = actor.getSelfTags() %} {% set actor_has_bio = actor.hasBio() %} {% set actor_uri = actor.getUri() %} +{% set actor_url = actor.getUrl() %} +{% set actor_is_local = actor.getIsLocal() %} +{% set mention = mention(actor) %} {% block profile_view %}
@@ -11,30 +14,28 @@
{% trans %} %actor_nickname%'s avatar. {% endtrans %} {{ actor_nickname }} - -
- {% if actor_has_bio %} - {{ actor.getBio() }} - {% else %} - {{ '(No bio)' | trans }} - {% endif %} -
+ {% if not actor_is_local %} +
+ {{ mention }} +
+ {% endif %} + +
+ {{ actor.getBio() }} +
+
{{ 'Subscribed' | trans }}{{ actor.getSubscribedCount() }}
{{ 'Subscribers' | trans }}{{ actor.getSubscribersCount() }}
{% for block in handle_event('AppendCardProfile', { 'actor': actor }) %}