diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 4116970f30..120164f9c2 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -215,7 +215,21 @@ class Note extends Entity public function getReplies(): array { - return Cache::getList('note-replies-' . $this->id, function () { return DB::dql('select n from App\Entity\Note n where n.reply_to = :id', ['id' => $this->id]); }); + return Cache::getList('note-replies-' . $this->id, function () { + return DB::dql('select n from App\Entity\Note n where n.reply_to = :id', ['id' => $this->id]); + }); + } + + public function getReplyToNickname(): ?string + { + if (!empty($this->reply_to)) { + return Cache::get('note-reply-to-' . $this->id, function () { + return DB::dql('select g from App\Entity\Note n join ' . + 'App\Entity\GSActor g with n.gsactor_id = g.id where n.reply_to = :reply', + ['reply' => $this->reply_to])[0]->getNickname(); + }); + } + return null; } public static function schemaDef(): array diff --git a/templates/note/view.html.twig b/templates/note/view.html.twig index c96e0cf29e..a122ebfdd6 100644 --- a/templates/note/view.html.twig +++ b/templates/note/view.html.twig @@ -1,9 +1,14 @@
+ {% set nickname = note.getActorNickname() %} - {{ note.getActorNickname() }}'s avatar + {{ nickname }}'s avatar - {{ note.getActorNickname() }} + {{ nickname }} + {% set reply_to = note.getReplyToNickname() %} + {% if reply_to is not null and not skip_reply_to is defined %} + {% trans with {'%name%': reply_to}%} in reply to %name% {% endtrans %} + {% endif %}
{{ note.getContent() }} @@ -41,7 +46,7 @@
{% for reply in note.getReplies() %} - {% include '/note/view.html.twig' with {'note': reply} only %} + {% include '/note/view.html.twig' with {'note': reply, 'skip_reply_to': true} only %} {% endfor %}